CTC Discussion on MPI Basics; Six Basic Calls
1.2.5 Receiving a message
Message passing in MPI-1 requires two-way communication.
One-sided communication is one of the features added in MPI-2.
Each time one process sends a message, another process must explicitly
receive the message. So for every place in your application that you call
an MPI send routine, there will be a corresponding place where you call an
MPI receive routine. Care must be taken to ensure that the send and
receive parameters match. This will be discussed in more detail later
in the module.
Like MPI_SEND, MPI_RECV is blocking. This means the call does not return
control to your program until all the received data have been stored in
the variable(s) you specify in the parameter list. Because of this, you
can use the data after the call and be certain it is all there.
(There are non-blocking receives where this is not the case.)
- C
- int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
- Fortran
- MPI_RECV(buf, count, datatype, source, tag, comm, status, ierror)
<type> buf(*)
integer count, datatype, source, tag, comm, status(MPI_STATUS_SIZE), ierror
The parameters:
- buf is the beginning of the buffer where the incoming data are to
be stored. For Fortran, this is often the name of an array in your
program. For C, it is an address.
- count is the number of elements (not bytes) in your receive buffer
- datatype is the type of data
- source is the rank of the process from which data will be accepted
(This can be a wildcard, by specifying the parameter MPI_ANY_SOURCE.)
- tag is an arbitrary number which can be used to distinguish among messages
(This can be a wildcard, by specifying the parameter MPI_ANY_TAG.)
- comm is the communicator
- status is an array or structure of information that is returned.
For example, if you
specify a wildcard for source or tag, status will tell you the actual rank or
tag for the message received
- ierror is a return error code