Your mission for this assignment is to improve the programs you wrote for Homework 1, and to write a version in OpenCL, and to measure their performance and accuracy more systematically.
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:
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.)
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).
(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
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.
Now revise the code you submitted for Homework 1 to use your RNG, and write versions in Java and in C with OpenCL. The OpenCL version should take one additional command-line argument, namely the number of samples (loop iterations) per work-item. 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 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
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.
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).
(NOTE: For the OpenCL version, what you will be varying is
the number of samples (loop iterations) per work-item.
You can either use that as the
axis of your plot, or determine
the number of work-items and use that.)
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'').