View the step-by-step solution to:

# CSci 5451, S'2010 1 Programming Assignment # 3 Due Date: April 26th, 2010 Background This lab is about Markov chain models and it will implement and...

a. You could also have a one dimensional mapping (stripe the domain in, say the horizontal
direction and assign each stripe to a process. When is it (likely to be) advantagous to use the
cartesian grid topology versus the striped topology?
b. Explain why there is a danger of deadlock when exchanging boundary points (“ghost cells”)
with sends and receives and how you managed to avoid the deadlock.
c. For main2.c provide the two timing plots (time versus p) and comment on what you see.
How does this relate to scaled speed–up? What would you expect to see for the case of the fixed
number of iterations in an ideal world of zero overhead? From the third plot, can you explain
how the efficiency deteriorated with the realistic situation of main2.c. What makes the second
curve worse than the first? Any conclusions on scaled speed-up in the iterative context?
d. In theory it should not be necessary to scale the probability vector at the end. Why? Why
may it still be a good idea to do so?
e. The lab illustrates a basic approach to sparse matrix computations in parallel. It implements
an iterative appro

CSci 5451, S’2010 Programming Assignment # 3 Due Date: April 26th, 2010 1 Background This lab is about Markov chain models and it will imple- ment and test a “random walk on a 2-D Grid”. Consider the grid pictured on the next Figure. The fgure shows a cartesian network grid and a particle. At any given time the particle can jump to any o± its nearest neighbors in the horizontal or vertical direction with di²erent prob- abilities; ±or example 0.3 going north, 0.2 going south, 0.1 going west, 0.2 going east, and 0.2 remaining where it is. One can think o± a particle starting in a certain position in the grid (in this assignment it will start at the origin) which then makes a hop to one o± its neighbors either north, south, to the west, to the east or to the point itsel± (i.e. remains at this point ±or one hop). i,j i+1,j i,j+1 i-1,j i,j-1 The problem is to determine the probability that the particle will be at any given node a±ter a very long time. A “state” is the location o± the particle within the grid. When the particle jumps to another node it changes states. The matrix P o± transition propabilities is defned by p ij = probability ±or a state to jump ±rom state i to state j . States are ordered in row major order on a grid. So, assuming an n × n grid, the grid-point (0,0) corresponds to sate 0, the point (0,1) to state 1, . .., the point (0 ,n - 1) to state n - 1, the point (1 , 0) to state n etc. .. So fxing i in ( i,j ) corresponds to moving East-West and fxing j corresponds to moving North-South. The method consists o± taking a given initial probability vector and then to iterate: u k +1 = u k P ±or a certain number o± steps until u k converges. There±ore, the basic problem is one o± per- ±orming a number o± matrix-vector products. The fnal result is a vector o± probabilities. 2 Details Each point o± the grid is assigned a set o± probabilities (WEST,EAST,SOUTH,NORTH) where WEST is the probability that when a particle is at this point it will hop to the west, EAST is probability that it hops to the east and so on. The probability that a particle will stay at the same location (termed “REMAIN”) ±or one hop is REMAIN = 1 - ( WEST + EAST + SOUTH + NORTH ). Each point in the grid may have a di²erent set o± probabilities. We will label by (R,W,E,S,N) the fve probabilities corresponding to remain, west, east, south, and north respectively. Assume that a particle starts at state k . We want to fnd what is the probability that a±ter m hops the particle will end at any given point. Let u 0 = (0 , 0 ,..., 1 , 0 , 0 ,... 0) where the “1” is located at position k - 1 (indices start at zero as in the C/C++ language). Then u 0 can be
viewed as a vector of probabilities where u 0 ( i ) is the probability that the particle is at point i after 0 hops (in this case probabilities are all zero except for state k ). Probabilities after 1st hop are obtained by computing u 1 = u 0 * P . Repeated multiplications by P in this way m times will yield the probability vector after m hops. The goal of the lab is to compute the vector of probabilities and see to which limit it will converge. 2.1 Topology You will need to implement the code with a cartesian 2-D mesh topology as illustrated in the next Figure. Suppose we have a logical grid of p processors, with p = px * py , px being the number of processes in the horizontal direction and py the number of processes in the vertical direction. In fact we will assume a torus connection (wrap around connections at edges in hori- zontal and vertical directions). Each processor sets the 5 probabilities (R,W,E,S,N) of each node assigned to it and must calculate the part of the probability vector for these points. Your program should work for any situa- tion when px * py is equal to the number of processes p (as entered by mpirun ) and quit with an error otherwise. You will need to assign a grid of size nx × ny to each process ( i,j ) for j = 0 , · · · ,px - 1, i = 0 , · · · ,py - 1. (Note: j is an index for the x direction). The values of nx and ny can be set in the program (see description of drivers below). On the other hand px and py should be read by the main program either from standard input (from the root node) or from a ±le called “inputs” which contains the two integers (feel free to have other parameters read from this ±le). You will be given a function double* get prob(double *prob,int i,int j,int nx,int ny,int px,int py,int *dims) that generates for any given i,j,nx,ny,px,py the 5 probabilities (R,W,E,S,N), discussed above into the one-dimensional array (of 5 entries) prob. The initial probability should be set to zero everywhere except at the origin where it is equal to one. So the particle is located at the origin at the start. 2.2 Main components and drivers You will need to provide two main drivers ( main1.c, main2.c ) and an auxiliary ±le of functions ( aux.c ). First driver. The ±rst driver, call it main1.c should do a number of iterations and stop when the distance between 2 consecutive probability vectors is less than a certain tolerance ǫ , or the total number of iterations exceeds a maximum M . After each iteration (i.e. calculation of the new probability vector) each processor will calculate max | u k ( i ) - u k - 1 ( i ) | for its part of the probability vector and then use the Allreduce operation to calculate max | u k ( i ) - u k - 1 ( i ) | 2
Show entire document

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents