I am working on a much bigger program where I struggle with MPI_Gather.
I wrote a minimal example code, see below.
program test
use MPI
integer
The big problem is that you did not include the last arg ierr in the call to MPI_Gather
. The doc said
All MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list.
In addition to that, my advise is to always stick to good practice: Do not use intrinsic funtion names for your variable, example of size
.
program test
use MPI
integer :: ierr, rank, nProc
double precision, allocatable, dimension(:) :: send, recv
call MPI_Init(ierr)
if (ierr /= 0) print *, 'Error in MPI_Init'
call MPI_Comm_size(MPI_COMM_WORLD, nProc, ierr)
if (ierr /= 0) print *, 'Error in MPI_Comm_size'
call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
if (ierr /= 0) print *, 'Error in MPI_Comm_size'
allocate(send(1), recv(nProc))
send(1) = rank
call MPI_Gather(send, 1, MPI_DOUBLE_PRECISION, &
recv, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)
if (ierr /= 0) print *, 'Error in MPI_Gather'
print *, recv
call MPI_Finalize(ierr)
end program test
You have forgotten to add the return error code to the call to MPI_Gather
as the last argument. The value of the return code is being written to an unmapped address.
It should read
call MPI_Gather(send, 1, MPI_DOUBLE_PRECISION, &
recv, 1, MPI_DOUBLE_PRECISION, 0, MPI_COMM_WORLD, ierr)
ifort catches this at the compilation stage. It looks like your compiler (gfortran?) doesn't