First page Back Continue Last page Summary Graphics
FORTRAN Example
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
INCLUDE 'mpif.h'
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr)
call MPI_COMM_SIZE(MPI_COMM_WORLD,np,ierr)
print *, 'Process ', myid, ' of ', np
n = 10000000
call MPI_BCAST(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
h = 1.0/n
sum = 0
do i = myid+1,n,np
x = h * (i - 0.5)
sum = sum + 4/(1+x**2)
enddo
call MPI_REDUCE(h*sum,pi,1,MPI_DOUBLE_PRECISION,
| MPI_SUM,0,MPI_COMM_WORLD,ierr)
if (myid.eq.0) print *,'pi=',pi,
| ' err=',pi - 3.141592653589793238462643
call MPI_FINALIZE(ierr)
END
- See Appendix C for a more complete example
Notes: