Slaves For Monte Carlo Example


The bad news is that we need four different slave programs, one for each quadrant. The good news is that they are very simple and you have change only a couple of lines to make the source for one quadrant into the source for another.

The tasks all the slaves have to do.

  1. Generate two random numbers in the appropriate quadrant.
  2. Use the border relation for this quadrant to check if the point defines by the two random numbers is inside the figure or not.
  3. If point is inside the figure increase a counter by one.
  4. Go back to step one until a set number of points has been checked.
  5. Sent the value of the counter back to the master.
  6. Ask master if there are more points to check for this quadrant,
The only thing you have to change for the different versions of the slave program is the range of the random numbers, so the points fall in the right quadrant, and the relation which describes the border of the figure in this quadrant.

The source codes for this program in C for,


Previous: The Master, it's getting a little bit more complicated
Next: A possible result
Index: Getting started with PVM