Suppose we toss darts randomly at a square dartboard, whose bullseye is at the
origin, and whose sides are 2 feet in length. Suppose also that there’s a circle
inscribed in the square dartboard. The radius of the circle is 1 foot, and it’s area
is π square feet. If the points that are hit by the darts are uniformly distributed
(and we always hit the square), then the number of darts that hit inside the circle
should approximately satisfy the equation
This is called a “Monte Carlo” method, since it uses randomness (the dart
tosses).
Write an MPI program that uses a Monte Carlo method to estimate π.
Process 0 should read in the total number of tosses and broadcast it to the
other processes. Use MPI Reduce to find the global sum of the local variable
number in circle, and have process 0 print the result. You may want to use
long long ints for the number of hits in the circle and the number of tosses,
since both may have to be very large to get a reasonable estimate of π.