CSCI 3366 (Introduction to Parallel and Distributed Processing), Spring 2011:
Homework 2

Credit:
40 points.

Overview

Your mission for this assignment is to improve the programs you wrote for Homework 1 and to measure their performance and accuracy more systematically.

Details

Thread-safe RNG

Your first step will be to write a thread-safe random number generator, i.e., one that can be called from multiple threads concurrently without ill effects. Here are some descriptions of simple algorithms you could use:

Or you may find something you like better, but if so, please check with me before implementing it.

You will need two implementations of whatever algorithm you choose, one in C and one in Java. I recommend that you just have your generator produce doubles in the desired range (between 0.0 and 1.0), rather than having it produce an integer that you then convert to a double as in the current C program. Notice that C offers an unsigned 32-bit integer type (unsigned int) that may be useful. Java does not, but it has a 64-bit integer type (type long). C (the C99 version) also has an at-least-64-bit integer type long long.

You will have to think a little about what state you need to retain between calls to your generator and where to keep it. (E.g., for the LCG algorithm, the state should probably consist of a single integer.)

Revised sequential programs

Code

Now replace the current code for generating random numbers in the two sequential programs from Homework 1 with calls to your RNG. (If you didn't already test your RNG code, you might temporarily put in some debug-print statements to be sure it's generating reasonable output.) The two programs should now produce the same output (except for execution time).

Results (accuracy)

(You only need to do this for one of your sequential programs, since they should give the same results.) Experiment until you find a seed that seems to give reasonable results, and then measure the relationship between accuracy (difference between the computed value of $ \pi$ and the constant as defined in the math library) and number of samples: Generate output for at least six different values of ``number of samples'' (I recommend starting with a medium-size number and then repeatedly doubling it, rather than increasing by a fixed amount). Plot the results, by hand or with whatever program you like. (I use gnuplot.) You can repeat this for more than one seed and plot all sets of results if you like.

Revised parallel programs

Code

Now revise the code you submitted for Homework 1 to use your RNG. As we noted in class, having all UEs generate points in the same sample space using the same RNG and seed is not useful. You have two options for dealing with this:

(You could try both, for extra credit, but one will suffice.) All three programs should produce the same output (except for execution time) for the same number of UEs.

Results (accuracy)

(You only need to do this for one of your parallel programs, since they should give the same results.) Experiment until you find a seed and number of samples that seem to give good results, and then measure the relationship between accuracy (difference between the computed value of $ \pi$ and the constant as defined in the math library) and number of UEs. Generate output for at least six different values of ``number of UEs'' (I recommend powers of two, starting with one). Plot the results, again by hand or with whatever program you like.

Results (performance)

For the values of seed and number of samples you used above, measure execution times for both sequential programs and all three parallel programs. For the parallel programs, measure execution times using different numbers of UEs (start with one and double until you notice that execution time is no longer decreasing). You should do each measurement more than once; if you get wildly different results it probably means you are competing with other work on the machine and should try again another time or using another machine or machines. Plot the results, again by hand or with whatever program you like: For each parallel program, plot execution time versus number of UEs, and also show execution time for the sequential program in the same base language (C or Java).

What to turn in and how

Turn in the following:

Submit your program source code by sending mail to bmassing@cs.trinity.edu. Send program source as attachments. You can turn in your plots and input data as hardcopy or by e-mail; if you send them by e-mail, just be sure they're in some format that can be read on one of the Linux lab machines. Please use a subject line that mentions the course number and the assignment (e.g., ``csci 3366 homework 2'').



Berna Massingill
2011-02-24