CPSC 626: Parallel Algorithm Design and Analysis
Programming Assignment #1
Fall 2008
Due: Thursday October 2, 2008 before class
General Guidelines for Programming Assignments
-
Programs should be written using good programming style
and should be well documented.
-
Code will be turned in electronically using the
turnin program on CSNET.
-
Everyone must turn in their own code. You may work with others (this is
encouraged), but you must reference your sources.
The objective of this programming assignment is to get you
familiar with parallel programming in general, and
with the IBM p575 cluster hydra.tamu.edu in particular.
You will use two different styles of parallel
programming - shared memory (OpenMP) and message passing (MPI).
So, you will actually need to write two different programs.
Recall the prefix sums problem: given a sequence of numbers
x1, x2, ..., xn,
the
prefix sums are the partial sums
s1 = x1
s2 = x1 + x2
...
sn = x1 + x2 + ... + xn
The Assignment
You should write programs to compute the prefix sums
on hydra.tamu.edu. Actually, you will write two programs,
one in shared memory (OpenMP) and one in message passing (MPI).
-
Your program should be able to use a variable, user-specified,
number of processors.
For example, the user should be able to run the program using
any number of processors between 1 and 16.
The number of processors can either be selected using a command
line argument or the program can prompt the user.
-
Your program should be able to sum a variable, user-specified,
number of integers.
The integers in the input sequence should be randomly generated
inside your program.
(That is, the user will input n, and the program will
then randomly generate n numbers.)
-
Your program should print out (either to the standard output or
to a file) the prefix sums computed.
-
Your program should print timing statistics.
In particular, you should print out the elapsed time taken
to compute the prefix sums, i.e., do not include the
time taken to generate the input sequence (or at least account
for it separately).
Sample Programs
You can find below sample programs for summing n numbers using the
OpenMP and MPI packages.
You should find things self explanatory.
There is a README file which tells you how to compile and run the programs.
The summation program itself is called sum.openmp.c or sum.mpi.c
for the C programs (or sum.openmp.cpp or sum.mpi.cpp for the C++ programs).
It is suggested that you start with these programs and modify them to
perform the parallel prefix.
The sample programs generate a random sequence of integers, print out
each processor's sum, and print out timing statistics - so you should
be able to reuse much of that.
Useful Resources
You may find the following web resourses helpful: