next up previous
Next: Collective Communication Functions Up: Point-to-point Communication Functions Previous: Send Functions

Receive Functions

  There is only one receive function in MPI, with the following prototype:

int MPI_Recv(void *buf, int count, MPI_Datatype datatype, 
int source, int tag, MPI_Comm comm, MPI_Status *status)
MPI_Recv posts a receive for a message from source ranked source, with a tag tag, on communicator comm, and waits for the message to arrive. The incoming message is put in buf, which is a buffer of count elements of datatype datatype. The buffer pointed to by status contains information on the completed operation i.e. how many elements were actually received. It is possible to receive a message from any process in the communicator by specifying source as the constant MPI_ANY_SOURCE. Similarly, it is possible to receive a message with any tag by specifying tag as the constant MPI_ANY_TAG. Any message satisfying the conditions specified by source and tag is accepted as the matching message, provided the in-order delivery rules are obeyed. There are two in-order delivery rules: (a) If a sender sends two message in succession to the same destination, and both match the same receive, then this operation cannot receive the second message if the first is still pending, and (b) If a receive posts two receives in succession, and both match the same message, then the second receive cannot be satisfied by this message, if the first one is still pending.

As with send functions, there is a corresponding non-blocking call for the receive function, called MPI_Irecv (for immediate receive). MPI_Irecv simply posts a receive, but does not wait for a matching message to arrive. It has the following prototype:

int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, 
int source, int tag, MPI_Comm comm, MPI_Status *status, 
MPI_Request *request)
request is the handle of the receive operation. Also as with the send functions, MPI_Wait can be used to wait for the operation to complete, which in this case is the arrival of the message.



next up previous
Next: Collective Communication Functions Up: Point-to-point Communication Functions Previous: Send Functions



Andy Kahn
Wed Jun 25 20:28:02 PDT 1997