Problem
I'm building a simple MPI Send/Recv hello world in Fortran and am running into an odd error. I want to make sure I'm not missing anything trivial before blaming OpenMPI or gfortran.
In the code below I send a simple array between two MPI processes. The first few entries of the data aren't sent correctly. The tail is fine.
Sent 1 2 3 4 5 6 7 8
Received 0 0 32 0 5 6 7 8
I expect sent
to equal received
and it does so after the first few entries.
Environment
These results come from gfortran-4.6.3
and openmpi-1.6.4
. A colleague ran this using ifort 13.0.1
and obtained correct results.
Code
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