Commit 73cc9da0 by Neil Gershenfeld

### wip

parent e95d406f
Pipeline #4918 passed with stage
in 0 seconds
 # # # mpipi.py # mpipi2.py # Neil Gershenfeld 2/6/20 # Neil Gershenfeld 2/6/20 # calculation of pi by an MPI Numba sum # calculation of pi by an MPI Numba sum # pi = 3.14159265358979323846 # pi = 3.14159265358979323846 ... @@ -9,6 +9,13 @@ import time ... @@ -9,6 +9,13 @@ import time from numba import jit from numba import jit from mpi4py import MPI from mpi4py import MPI NPTS = 1000000000 NLOOP = 10 comm = MPI.COMM_WORLD rank = comm.Get_rank() nproc = comm.Get_size() @jit(nopython=True) @jit(nopython=True) def calc(istart,iend): def calc(istart,iend): sum = 0.0 sum = 0.0 ... @@ -16,22 +23,26 @@ def calc(istart,iend): ... @@ -16,22 +23,26 @@ def calc(istart,iend): sum += 0.5/((i-0.75)*(i-0.25)) sum += 0.5/((i-0.75)*(i-0.25)) return sum return sum NPTS = 100000000000 comm = MPI.COMM_WORLD rank = comm.Get_rank() nproc = comm.Get_size() if (rank == 0): if (rank == 0): start_time = time.time() istart = 1+rank*NPTS; istart = int(1 + NPTS*((rank+0)/nproc)) iend = (rank+1)*NPTS; iend = int(NPTS*((rank+1)/nproc)) max = 0 pi = calc(istart,iend) for j in range(NLOOP): comm.reduce(pi,op=MPI.SUM,root=0) comm.Barrier() end_time = time.time() start_time = time.time() mflops = NPTS*5.0/(1.0e6*(end_time-start_time)) sum = 0.0; print("NPTS = %d, pi = %f"%(NPTS,pi)) sum = calc(istart,iend) print("time = %f, estimated MFlops = %f"%(end_time-start_time,mflops)) pi = comm.reduce(sum,op=MPI.SUM,root=0) end_time = time.time() mflops = nproc*NPTS*5.0/(1.0e6*(end_time-start_time)) print("processes = %d, NPTS = %d, pi = %f"%(nproc,NPTS,pi)) if (mflops > max): max = mflops print("time = %f, estimated MFlops = %f, max = %f"%(end_time-start_time,mflops,max)) else: else: istart = int(1 + NPTS*((rank+0)/nproc)) istart = 1+rank*NPTS iend = int(NPTS*((rank+1)/nproc)) iend = (rank+1)*NPTS pi = calc(istart,iend) for j in range(NLOOP): comm.reduce(pi,op=MPI.SUM,root=0) comm.Barrier() sum = calc(istart,iend) comm.reduce(sum,op=MPI.SUM,root=0)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!