56 FortranÀý×Ó£¨¼ÌÐø£© |
c check for quit signal if ( n .le. 0 ) goto 30c calculate the interval size h = 1.0d0/n
sum = 0.0d0 do 20 i = myid+1, n, numprocs x = h * (dble(i) - 0.5d0) sum = sum + f(x) 20 continue mypi = h * sum
c collect all the partial sums call MPI_REDUCE(mypi,pi,1,MPI_DOUBLE_PRECISION,MPI_SUM,0, $ MPI_COMM_WORLD,ierr)
c node 0 prints the answer. if (myid .eq. 0) then write(6, 97) pi, abs(pi - PI25DT) 97 format(' pi is approximately: ', F18.16, + ' Error is: ', F18.16) endif
goto 10
30 call MPI_FINALIZE(rc) stop end
Copyright: NPACT |