program main
include 'mpif.h'
character * (MPI_MAX_PROCESSOR_NAME) processor_name
integer myid, numprocs, namelen, rc,ierr
real*8 homepi
call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
call MPI_GET_PROCESSOR_NAME(processor_name, namelen, ierr)
homepi=1.0
if(myid.NE.0)then
call MPI_REDUCE(homepi, homepi,1, MPI_DOUBLE_PRECISION,
& MPI_SUM, 0, MPI_COMM_WORLD, ierr )
else
call MPI_REDUCE(MPI_IN_PLACE, homepi,1, MPI_DOUBLE_PRECISION,
& MPI_SUM, 0, MPI_COMM_WORLD, ierr )
write(*,33) homepi
33 format(' sum value of pi = ',f10.8)
endif
call MPI_FINALIZE(rc)
end
QQ截图20200324114458.png (10.22 KB, 下载次数: 325)
捕获.JPG (47.55 KB, 下载次数: 340)
运行结果截图
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |