MPI Assignment: Parallelizing Codes using MPI - Diffusion Equation and Mandelbrot Set - Pr, Assignments of Computer Science

An mpi assignment for csi 702 students, which involves completing two problems using mpi for parallelization. The first problem is the diffusion equation, where students need to write a serial code, modify it for mpi, and analyze performance. The second problem is the mandelbrot set, where students must create a parallel version using the manager/worker programming pattern. The document also mentions an n-body assembly line and parallel sort problem.

Typology: Assignments

Pre 2010

Uploaded on 02/10/2009

koofers-user-ze8
koofers-user-ze8 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MPI and Sockets
CSI 702- Fall 2008 - Assignment 3 Due: Wednesday October 15
Overview
For this assignment, you will experiment with several of the code tuning
techniques we covered in class. You may write your codes in C, C++, or
Fortran. The timing results should be done using the profilers for the ap-
propriate compiler. The final assignment will be turned in at the beginning
of class. Electronic submissions will not be allowed for this assignment, and
there will be a penalty for late submission.
NOTE: October 15 is the night of our midterm exam. Elements of these
assignments may be included as part of this exam.
Requirements:
For this assignment, you will need to
Complete TWO of the FOUR problems in this assignment.
You may use C, C++, or Fortran for the serial code.
You MUST use MPI to parallelize the code.
You need to create both a serial and parallel version of each code.
You need to have a write up for each problem that documents
The parallel approach taken
The problems you had during the implementation
A quick summary of the MPI commands used
A performance analysis of the code, including changing the prob-
lem size and the number of nodes that the code runs on
Comparisons to the serial code of the performance and easy of
implementation
Comparisons of the output of the serial and parallel codes. This
might include visualization - if appropriate - of the results. Are
the results identical?
Extra credit - complete any of the problems (including one you did
using MPI) using Sockets and Threads. This code will need to fork to
at least four processes, although they will all be on the same machine.
1
pf3
pf4
pf5

Partial preview of the text

Download MPI Assignment: Parallelizing Codes using MPI - Diffusion Equation and Mandelbrot Set - Pr and more Assignments Computer Science in PDF only on Docsity!

MPI and Sockets

CSI 702- Fall 2008 - Assignment 3 Due: Wednesday October 15

Overview For this assignment, you will experiment with several of the code tuning techniques we covered in class. You may write your codes in C, C++, or Fortran. The timing results should be done using the profilers for the ap- propriate compiler. The final assignment will be turned in at the beginning of class. Electronic submissions will not be allowed for this assignment, and there will be a penalty for late submission. NOTE: October 15 is the night of our midterm exam. Elements of these assignments may be included as part of this exam.

Requirements: For this assignment, you will need to

  • Complete TWO of the FOUR problems in this assignment.
  • You may use C, C++, or Fortran for the serial code.
  • You MUST use MPI to parallelize the code.
  • You need to create both a serial and parallel version of each code.
  • You need to have a write up for each problem that documents
    • The parallel approach taken
    • The problems you had during the implementation
    • A quick summary of the MPI commands used
    • A performance analysis of the code, including changing the prob- lem size and the number of nodes that the code runs on
    • Comparisons to the serial code of the performance and easy of implementation
    • Comparisons of the output of the serial and parallel codes. This might include visualization - if appropriate - of the results. Are the results identical?
  • Extra credit - complete any of the problems (including one you did using MPI) using Sockets and Threads. This code will need to fork to at least four processes, although they will all be on the same machine.

1 Diffusion Equation

The diffusion equation is a simple parabolic partial differential equation that can be solved numerically using a finite difference method.

dφ dt

= κ ▽^2 φ

in one dimension

dφ dt

= κ

d^2 φ dx^2

The simple finite difference representation of this equation is in one di- mension

φi,j+1 − φi,j k

= κ

φi+1,j − 2 φi,j + φi− 1 ,j h^2

or

φi,j+1 = φi,j + κ

k h^2

(φi+1,j − 2 φi,j + φi− 1 ,j )

φi,j+1 =

( 1 − 2 κ

k h^2

) φi,j +

( κ

k h^2

) (φi+1,j + φi− 1 ,j )

where h is the spatial grid size, k is the time-step size, and κ is a diffusion coefficient. For this problem, let

xmin = 0 xmax = 1 φ(xmin) = 0 φ(xmax) = 0 κ = 1 k = 0. 2 × h^2 t 0 = 0 tf inal = 0. 5

It is important to note that some starting points will never reach C > 2, so a maximum iteration number is needed in the problem (500 iterations, for example.) For this problem, you are to make a parallel version of the Mandelbrot problem that uses the manager/worker programming pattern. You cannot use the fine grain scatter decomposition we discussed in the notes for this problem.

  1. Write a simple C or Fortran code to calculate the Mandelbrot set. Find the number of iterations needed to exit a given point in the complex plane using the iterative mapping described above. Use a maximum cutoff for the iterations of 500 cycles. You should have the user input the number of points (n) in the x and y direction at the beginning of the code, then divide the sampling points into an n × n grid.
  2. Modify the code to work under MPI using a manager/ work paradigm.

(a) To do this, you should designate node 0 to manage the work load. (b) Each CPU will be given an initial parcel of work to do. (c) Processor 0 will then listen for communications from the others using asynchronous communication. (d) When any processor finishes its work block, it should send a mes- sage to processor 0 asking for another block. At the same time, it should send its results back to node 0 so they can be output to a file. It should go in a receive state to get the message from node 1 about which block to do. (e) Processor 0 will assign the processor a new block, and update the list of things left to do. If there are no blocks left to be calculated, then it should tell the CPU to exit.

  1. You will need to experiment with the block sizes and resolutions for a given set of CPU’s.

3 N-body Assembly Line

In this problem, you will solve the gravitational potential for a set of particles using an assembly line programming paradigm.

The gravitational potential for a given particle is given by the equations

φj =

∑^ n

i=1,i 6 =j

−GMiMj Rij

So, to calculate the gravitational potential, you need to have a loop over all the particles like

for j = 1:n potential(j) = 0 for i = 1:n if (i /= j) then R_ij = sqrt( (x(i) - x(j))^2 + (y(i)-y(j))^2) + (z(i)-z(j))^2) potential(j) = potential(j) -G * M(j) * M(i)/ Rij endif enddo enddo

To do this in parallel, you will use the “assembly line” programming pattern. Assume you are running n particles over nproc processors

  1. Generate random positions for n/nproc particles for each of nproc files. The file names should be named “particle0”, “particle1”, “particle2”, etc where the number designates the processor ID associated with the file. You can (and perhaps should) generate the particle data with a serial code. If you do the generation in parallel, be aware that you must worry about how the random number generator works on each CPU. Assume the masses for all the particles are 1, and the gravitational constant is 1 as well. For calculational ease, assume the x,y, and z coordinates range from 0 to 1.
  2. Write a serial code that reads in all the data files, and calculates the potential for each particle. The code should write out the potentials into a single file, and return the minimum and maximum potential for the entire set of particles.
  3. Convert the code to use MPI.