Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Implementing and Analyzing Parallel Solutions to the N-Queens Problem using MPI - Prof. Ti, Exams of Computer Science

The implementation and analysis of two las vegas style algorithms to find a single solution to the n-queens problem using mpi. Pseudo-code for both algorithms and discusses the challenges of determining an effective exit strategy for the parallel solution. A comparison to dr. Rolfe's java threads implementation is also mentioned.

Typology: Exams

Pre 2010

Uploaded on 08/19/2009

koofers-user-rzo
koofers-user-rzo 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MPI: Las Vegas
A Probabilistic Look At N-Queens
Joshua Patterson
I will be implementing and analyzing two simple Las Vegas style algorithms that
find a single solution to the N-Queens problem. Since Dr. Timothy Rolfe has already
implemented these algorithms using Java threads, it may be worthwhile to test the
performance of an implementation that uses MPI and compare it to Dr. Rolfe’s results.
Pseudo-code for the algorithms can be found on the following page.
Algorithm one:
The first algorithm works with three vectors. One is a permutation vector that
holds the column position of each queen. The other two vectors contain Boolean values
that mark which diagonals are in use.
To start the algorithm, the permutation vector is randomized and both diagonal
vectors are set to false. Then the first queen’s diagonals are marked true. The next, and
each subsequent queen’s position must first be checked to see if she lies on a used
diagonal. If she does not, move on to the next row. However, if she does lie on a used
diagonal, swap her row with row + 1. If her position is used as well, keep swapping with
row the next row until either a queen is found that does not lie on a used diagonal, or all
remaining queens have been tested. If no queen is found, the algorithm starts over
Algorithm two:
The second algorithm starts with an NxN Boolean matrix representing a board
with all positions marked as unblocked. A queen is then placed in row 0 at a random
position, and that queen’s column and diagonals are then marked as blocked as blocked
on the board.
Each subsequent queen is then placed at a random unblocked position on the next row.
If no unblocked position is found, the board is scrapped and the algorithm starts with a
new board.
Parallel solution:
Both algorithms can easily be broken into parallel processes simply by ensuring
that the random number generator in each process is given a sufficiently different seed.
The main challenge for the assignment will be determining a good exit strategy. Each
machine must be signaled to stop when a solution is found.
Dr. Rolfe’s analysis of his Java threads implementation can be found at:
http://penguin.ewu.edu/~trolfe/QueenLasVegas/
pf2

Partial preview of the text

Download Implementing and Analyzing Parallel Solutions to the N-Queens Problem using MPI - Prof. Ti and more Exams Computer Science in PDF only on Docsity!

MPI: Las Vegas

A Probabilistic Look At N-Queens

Joshua Patterson

I will be implementing and analyzing two simple Las Vegas style algorithms that

find a single solution to the N-Queens problem. Since Dr. Timothy Rolfe has already

implemented these algorithms using Java threads, it may be worthwhile to test the

performance of an implementation that uses MPI and compare it to Dr. Rolfe’s results.

Pseudo-code for the algorithms can be found on the following page.

Algorithm one:

The first algorithm works with three vectors. One is a permutation vector that

holds the column position of each queen. The other two vectors contain Boolean values

that mark which diagonals are in use.

To start the algorithm, the permutation vector is randomized and both diagonal

vectors are set to false. Then the first queen’s diagonals are marked true. The next, and

each subsequent queen’s position must first be checked to see if she lies on a used

diagonal. If she does not, move on to the next row. However, if she does lie on a used

diagonal, swap her row with row + 1. If her position is used as well, keep swapping with

row the next row until either a queen is found that does not lie on a used diagonal, or all

remaining queens have been tested. If no queen is found, the algorithm starts over

Algorithm two:

The second algorithm starts with an NxN Boolean matrix representing a board

with all positions marked as unblocked. A queen is then placed in row 0 at a random

position, and that queen’s column and diagonals are then marked as blocked as blocked

on the board.

Each subsequent queen is then placed at a random unblocked position on the next row.

If no unblocked position is found, the board is scrapped and the algorithm starts with a

new board.

Parallel solution:

Both algorithms can easily be broken into parallel processes simply by ensuring

that the random number generator in each process is given a sufficiently different seed.

The main challenge for the assignment will be determining a good exit strategy. Each

machine must be signaled to stop when a solution is found.

Dr. Rolfe’s analysis of his Java threads implementation can be found at:

http://penguin.ewu.edu/~trolfe/QueenLasVegas/

Pseudo-code provided by Dr. Rolfe

Algorithm one:

repeat set valid to true shuffle the current permutation vector set the two diagonal vectors to all false mark the row 0 queen in the two diagonal vectors for row = 1 to n- set test = row+ while this queen is on an in-use diagonal if test = n set valid to false break out of the while loop else swap positions row and test increment test end if/else end while if not valid break out of the for loop mark this row’s queen in the diagonal vectors end for loop until valid

Algorithm Two:

repeat set valid to true boolean matrix blocked[n][n] set to all false for row = 0 to n– randomly select col as an unblocked cell if there is NO unblocked cell set valid to false and break from for loop save col as part of the solution vector for all rows below the current row mark as blocked the col cell also diagonal cells blocked by [row][col] end for end for loop until valid