The most probable cause is that you pass an INTEGER
scalar as the actual status
argument to MPI_RECV
when it should be really declared as an array with an implementation-specific size, available as the MPI_STATUS_SIZE
constant:
INTEGER, DIMENSION(MPI_STATUS_SIZE) :: status
or
INTEGER status(MPI_STATUS_SIZE)
The message tag is written to one of the status fields by the receive operation (its implementation-specific index is available as the MPI_TAG
constant and the field value can be accessed as status(MPI_TAG)
) and if your status
is simply a scalar INTEGER
, then several other local variables would get overwritten. In your case it simply happens so that nstartg
falls just above status
in the stack.
If you do not care about the receive status, you can pass the special constant MPI_STATUS_IGNORE
instead.