HP-MPI User's Guide (11th Edition)
Example applications
compute_pi_spawn.f
Appendix A278
C Calculate the interval size.
C
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
C Collect all the partial sums.
C
call MPI_REDUCE(mypi, pi, 1, MPI_DOUBLE_PRECISION,
+ MPI_SUM, 0, mergedcomm, ierr)
C
C Process 0 prints the result.
C
if (myid .eq. 0) then
write(6, 97) pi, abs(pi - PI25DT)
97 format(' pi is approximately: ', F18.16,
+ ' Error is: ', F18.16)
endif
call MPI_COMM_FREE(mergedcomm, ierr)
call MPI_FINALIZE(ierr)
stop
end
compute_pi_spawn.f output
The output from running the compute_pi_spawn executable is shown
below. The application was run with -np1 and with the -spawn option.
Original Process 0 of 1 is alive
Spawned Process 0 of 3 is alive
Spawned Process 2 of 3 is alive
Spawned Process 1 of 3 is alive
Process 0 of 4 in merged comm is alive
Process 2 of 4 in merged comm is alive
Process 3 of 4 in merged comm is alive
Process 1 of 4 in merged comm is alive
pi is approximately: 3.1416009869231254
Error is: 0.0000083333333323