|
Homework 2 // Due at Lecture Mon Feb 13
You should do this assignment alone. No late assignments.
In this assignment, you will gain experience in writing explicit parallel programs
using two different programming styles - shared-memory and message passing.
You will use Pthreads for shared-memory programming and MPI for message passing.
You will do this assignment on malbec.cs.wisc.edu a Sun Enterpise T5120 Server containing a 64-thread Sun UltraSparc-T2 processor.
Run /usr/platform/sun4v/sbin/prtdiag -v on malbec, if you wish to learn more
about the machine.
Pthreads
POSIX threads or Pthreads is a library implementation of a standardized C threads API that enables
shared memory programming. In particular, the API provides two major functionalities -
- Thread Management: Functions for creating, detaching, joining threads etc...
- Synchronization: Mutexes, Conditional variables etc...
For more information on the Pthreads, check this tutorial from
Lawrence Livermore National Labs.
A friendly primer on using pthreads by Tristan Ravitch is available here.
The pthreads example program demonstrated in class is available for review here.
MPI
MPI is a library specification for message-passing, proposed as a standard for use on parallel computers, clusters and
heterogeneous networks. The MPI standard and related information is available at
http://www.mcs.anl.gov/mpi. An online reference to MPI can be found at
http://www-unix.mcs.anl.gov/mpi/www/. An MPI example program is available for review here.
It is strongly recommended that you download and run the examples early to get a hands-on experience of compiling,
linking and running Pthread and MPI programs.
For Pthread programs
- Include pthread.h in all the source files that use Pthread library calls.
- Use the flags -mt -lpthread for compilation and linking of your source files.
For MPI programs
- Include mpi.h in all the source files that use MPI library calls.
- Compile with the mpicc compiler located at /scratch/mpi/mpich2-1.0.8/bin/.
- Set your LD_LIBRARY_PATH to point to /scratch/mpi/mpich2-1.0.8/lib/.
- To run your MPI program, use mpiexec located at /scratch/mpi/mpich2-1.0.8/bin/.
- You may have to start mpi using mpd & located at /scratch/mpi/mpich2-1.0.8/bin/
If mpd asks you to create .mpd.conf, do so. Make sure the permissions are the way mpd is asking them to be, and
rerun mpd & after creating the file.
Programming Task: Ocean Simulation
We will re-use the Red/Black variant of Ocean Simulation program from the previous assignment.
Problem 1: Write Parallel Ocean using Pthreads(15 points)
Write a multi-threaded implementation of red/black Ocean using Pthreads. You could
choose to parallelize only the simulation phase of your program and not the initialization
phase. Make an argument for the correctness of your implementation.
Problem 2: Write Parallel Ocean using MPI (15 points)
For this problem, you will use MPI primitives to parallelize your sequential program.
Note that the processes in message-passing programs do not share
a single address space. So you will have to explicitly split your data structures between
the various processes. Again, make an argument for the correctness of your implementation
For simplicity, you may assume that the dimensions of the grid are
powers of two plus two, and that only N=[1,2,4,8,16,32,64] will be passed as the
number of threads.
Problem 3: Analysis of Ocean (20 points)
Modify your programs to measure the execution time of the
simulation phase of execution. Use of Unix's gethrtime() is
recommended for Pthread programs. Use MPI_Wtime() for timing your
MPI program.
Compare the performance of the simulation phase of your three Ocean implementations (Pthreads, MPI and OpenMP from Homework 1)
for a fixed number of time steps (100).
Plot the normalized (versus the sequential version of Ocean from Homework 1) speedups of
your implementations on N=[1,2,4,8,16,32,64] threads for a 514x514 ocean.
Note that the N=1 case should be the sequential
version of Ocean, not the parallel version using only 1 thread.
Repeat for an ocean sized to 1026x1026.
What to Hand In
Please turn this homework in on paper at the beginning of lecture.
Your answers to the discussion questions should be typed up,
no handwritten notes will be accepted. A tarball of your entire source code
including a Makefile and a README file, should be emailed to the TA before
the beginning of lecture.
Use subject line [CS/ECE 757] Homework 2,
so that email filters work properly.
- A printout of the source code of the simulation phase of Pthreads Ocean and a concise description of how you parallelized the program.
- A printout of the source code of the simulation phase of MPI Ocean and a concise description of the communication used in your program.
- Arguments for correctness of the two programs.
- The plots as described in Problem 3.
- A short paragraph on your experiences with parallelizing Ocean using the three different approaches (OpenMP, Pthreads and MPI).
Which approach was easiest in terms of programming effort? Which approach would you choose considering the programming effort, performance
and scalability of each implementation?
Tips and Tricks
- Start early.
- Set up RSA authentication on malbec to save yourself some keystrokes.
HowTo.
- Make use of the demo programs provided.
- You can use /usr/platform/sun4v/sbin/prtdiag -v on malbec to learn
many useful characteristics of your host machine.
- Run your programs multiple times to get accurate time measurements. This will help
avoid incorrect results due to interference with other user's programs.
Important: Include your name on EVERY page.
|