问题
我正在 Fortran 中构建一个简单的 MPI Send/Recv hello world,但遇到了一个奇怪的错误。在指责 OpenMPI 或 gfortran 之前,我想确保我没有遗漏任何琐碎的事情。
在下面的代码中,我在两个 MPI 进程之间发送了一个简单的数组。数据的前几个条目未正确发送。尾巴没问题。
Sent 1 2 3 4 5 6 7 8
Received 0 0 32 0 5 6 7 8
我希望sent相等received,并且在前几个条目之后它会这样做。
环境
这些结果来自gfortran-4.6.3和openmpi-1.6.4。一位同事使用ifort 13.0.1并获得了正确的结果。
代码
program main
implicit none
include 'mpif.h'
integer rank, size, ierr
call MPI_INIT( ierr )
call MPI_COMM_RANK( MPI_COMM_WORLD, rank, ierr )
call MPI_COMM_SIZE( MPI_COMM_WORLD, size, ierr )
! print *, 'Process ', rank, ' of ', size, ' is alive'
if (rank .eq. 0) then
call sender()
end if
if (rank .eq. 1) then
call recver()
end if
call MPI_FINALIZE( ierr )
end program
subroutine sender()
implicit none
include 'mpif.h'
integer i, ierr
integer dat(8)
do i=1, 8
dat(i) = i
enddo
call MPI_SEND( dat, 8, MPI_INTEGER, 1, 2001, MPI_COMM_WORLD, ierr )
print *, "Sent ", dat
end subroutine
subroutine recver()
implicit none
include 'mpif.h'
integer i, ierr
integer stat
integer dat(8)
dat = -1
print *, "Empty ", dat
call MPI_RECV( dat, 8, MPI_INTEGER, 0, 2001, MPI_COMM_WORLD, stat, ierr )
print *, "Received ", dat
end subroutine