CSCI 3366 (Introduction to Parallel and Distributed Processing), Fall 2006:
Homework 1
- Assigned:
- September 11, 2006.
- Due:
- OpenMP program: September 18, 2006, at 11:59pm.
- MPI program: September 22, 2006, at 11:59pm.
- Java program: September 27, 2006, at 11:59pm.
- Credit:
- 30 points.
First a reminder about something said in class:
In doing this assignment, please do not discuss
the problem or possible solutions with people who took
this course last year. I want you to discover the potential
pitfalls yourselves!
In class we briefly discussed approximating the value of
by ``throwing darts'' at a square of side 2 enclosing a circle of
radius 1, counting how many darts fall within the circle, and
then dividing that by the total number of darts to get the ratio
between the area of the circle (
) and the area of the
square (4).
For this assignment, your mission is to write, for each of
the programming environments we've talked about (OpenMP, MPI,
and Java), a parallel program that performs this calculation.
To get you started, I have written sequential programs in C and
Java that perform the desired calculation and print appropriate
results:
Start by downloading these two programs, compiling them,
and running them a few times to get a sense of what inputs
you need to get a good approximation of
.
Feel free to also tinker with the parts of the code that
generate the sequence of random numbers;
you may find some method you think will work better.
(For the C program, review the man pages for random
and drand48. For the Java program, review the API
(``Java docs'') for the Random class.)
The three programs you write (one each using OpenMP, MPI,
and Java) should accept the same command-line input and
produce the same output as my sequential programs, except that:
- The Java program should require an additional command-line
argument, the number of threads to use.
- Rather than printing ``sequential C/Java program results'',
- the OpenMP program should print
``parallel OpenMP program results with N threads''
(where N is replaced with the number of threads);
- the MPI program should print
``parallel MPI program results with N processes''
(where N is replaced with the number of processes);
and
- the Java program should print
``parallel Java program results with N threads''
(where N is replaced with the number of threads).
(You can make other changes to the output format if you
like, but be sure your code prints the same information
mine does.)
You can also make any changes you like to how the programs
work internally.
It's up to you how you choose to parallelize the sequential
code, but notice that in many respects the calculation here
strongly resembles the one in the numerical integration example,
so the approaches we used for that example might work well here too.
The only thing that's tricky is deciding what to do about the
random numbers (should all the processes/threads generate the
same sequence of random numbers? should they generate different
ones? if so, how?). For this assignment, I want you to make
your best guess about what would be reasonable, implement that,
and see how it works. After everyone has turned something in,
we'll discuss in class your results and possible improvements.
You can make my grading job a bit easier by using the following
names for your programs:
- monte-carlo-pi-mpi.c for the MPI program.
- monte-carlo-pi-openmp.c for the OpenMP program.
- MonteCarloPiParallel.java for the Java program.
In addition to turning in your source code, briefly answer
the following questions about each of your programs:
- Does the program seem to generally give better results
as the number of samples increases? Can you say anything
interesting or useful about how the seed affects the
quality of the results?
- For the same number of samples and seed, does the program
give the same results no matter how many processes or
threads you use? If not, why do you think it doesn't?
- Does parallelism seem to help the program's performance?
You will probably need a fairly large number of samples
to observe any benefit, but up to a point more processes
or threads should give faster execution. Is this true
for your program? Support this with some observations
(output of your program showing number of samples,
number of processes/threads, etc., plus the name(s) of
the machine(s) used). If it's not true, what do you
think is going wrong?
Keep in mind that this assignment is a first pass at producing
good programs for this problem. Your programs should compile and
produce output that's more or less reasonable, but you will have
another chance (in Homework 2) to produce something that really
works well, so it's okay this time if the output seems slightly off,
or the performance is disappointing.
- Feel free to borrow code
from any of the sample programs linked from the
course sample programs page.
This page also contains links to my writeups about
compiling and running programs on the lab machines.
The
course ``useful links'' page
has pointers to documentation on OpenMP, MPI, and Java.
- You can develop your programs on any system that provides the
needed functionality, but I will test them on the department's
Fedora Core 5 Linux machines, so you should probably make sure
they work in that environment before turning them in.
Submit your program source code and discussion of results
by sending mail to
bmassing@cs.trinity.edu.
Send program source as attachments.
You can put your discussion of results in the body of the message
or attach a file in any format readable on our Linux lab machines
(plain text, PDF, something openable with OpenOffice, etc.).
Please use a subject line that mentions the course number and
the assignment (e.g., ``csci 3366 homework 1'').
Berna Massingill
2006-09-22