MC
MPI version of a Monte Carlo Quadrature Program


MC is a program which should use MPI to speed up its estimate of an integral of the form

Integral ( unit hypercube ) F(X1,X2,...,XD) dx
However, the code you will see here is only a sequential version!

The program uses the Monte Carlo method, so it simply picks SAMPLE_NUM points at random in the unit hypercube, evaluates F at each point and takes the average.

You are to convert the program by adding the appropriate MPI calls ... and include statements ... anything else you need! You might want to define a few extra variables, to differentiate between "local" and "global" variables. In other words, each process will define an estimate of the integral, and then a total estimate will be made. The original variable was called Q but now it might help to distinguish between Q_local and Q_global.

Warning: you are working with a random number generator, which requires the use of a "seed" value. In parallel processing, you need to be careful to ensure that the multiple processes "share" the random number generator correctly. You don't want each process to compute the same string of random values!

Source Code:

Completed Source Code:

Here are "completed" versions of the programs.

Scripts:


You can go up one level to the FSU MPI 2008 web page.

Last revised on 17 September 2008.