MPI_Isend()函数会出现内存耗尽的情况吗?如何避免呢?考虑到通讯和计算叠加,除了MPI_Isend()之外,有没有其它更好用的函数?
我写了如下一段代码测试,在一台4GB的机器上开两个进程,进程1频繁向进程0发送数据,非阻塞通讯,正常结束。
结果表明,仅仅是MPI_Isend()的正规操作,应该不会出现内存耗尽情况。
但问题是,在实际应用中,程序修正到第2000多次时,我确实出现了out of memory错误。。。
module variable
integer,parameter:: imax = 50, jmax = 50, kmax = 400,
& itermax=9e+8
real(kind=8) buf(imax,jmax,kmax)
end module variable
program myprogram
use variable
implicit none
include 'mpif.h'
integer myid,other,numprocs
integer req,tag,ierr,status(MPI_STATUS_SIZE)
integer nn
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, myid, ierr)
! call MPI_COMM_SIZE(MPI_COMM_WORLD, numprocs, ierr)
numprocs = 2
if(myid.eq.1) other = 0
if(myid.eq.0) other = 1
if(myid.eq.0) print *,'itermax:',itermax
do nn = 1, itermax
tag = nn + 20
if(myid.eq.0) print *,nn
call MPI_Barrier(MPI_COMM_WORLD,IERR)
if(myid.eq.1) then
call computation()
call MPI_Isend(buf(1,1,1),imax*jmax*2,
& MPI_DOUBLE_PRECISION,other,tag,MPI_COMM_WORLD,req,ierr)
else
call MPI_Irecv(buf(1,1,1),imax*jmax*2,
& MPI_DOUBLE_PRECISION,other,tag,MPI_COMM_WORLD,req,ierr)
call computation()
call MPI_wait(req,status,ierr)
endif
enddo
print *,myid,'Finished!'
call MPI_FINALIZE(ierr)
end
subroutine computation()
use variable
integer i,j,k,t
do 1 i = 1, imax
do 1 j = 1, jmax
do 1 k = 1, kmax
buf(i,j,k) = (i+j+k)/2.d0
1 continue
end