3
THIS CODE WAS TAKEN FROM mpi4py-1.2.2/demo/compute-pi and converted to use
4
Global Arrays and ga.acc(). Thanks Lisandro!
6
Parallel PI computation using Remote Memory Access (RMA)
7
within Python objects exposing memory buffers (requires NumPy).
11
$ mpiexec -n <nprocs> python pi.py
14
from mpi4py import MPI
17
from math import pi as PI
18
from numpy import ndarray
22
prompt = "Enter the number of intervals: (0 quits) "
24
n = int(raw_input(prompt));
30
def comp_pi(n, myrank=0, nprocs=1):
33
for i in xrange(myrank + 1, n + 1, nprocs):
35
s += 4.0 / (1.0 + x**2);
39
message = "pi is approximately %.16f, error is %.16f"
40
print (message % (pi, abs(pi - PI)))
45
g_pi = ga.create(ga.C_DBL, [1])
48
if len(sys.argv) == 2:
62
mypi = comp_pi(n, myrank, nprocs)