MPI_Recv function

Performs a receive operation and does not return until a matching message is received.

Syntax

int MPIAPI MPI_Recv(
  _In_opt_ void         *buf,
           int          count,
           MPI_Datatype datatype,
           int          source,
           int          tag,
           MPI_Comm     comm,
  _Out_    MPI_Status   *status
);

Parameters

  • buf [in, optional]
    A pointer to the buffer that contains the data to be sent.

  • count
    The number of elements in the buffer. If the data part of the message is empty, set the count parameter to 0.

  • datatype
    The data type of the elements in the buffer array.

  • source
    The rank of the sending process within the specified communicator. Specify the MPI_ANY_SOURCE constant to specify that any source is acceptable.

  • tag
    The message tag that is used to distinguish different types of messages. Specify the MPI_ANY_TAG constant to indicate that any tag is acceptable.

  • comm
    The handle to the communicator.

  • status [out]
    On return, contains a pointer to an MPI_Status structure where information about the received message is stored.

Return value

Returns MPI_SUCCESS on success. Otherwise, the return value is an error code.

In Fortran, the return value is stored in the IERROR parameter.

Fortran

    MPI_RECV(BUF, COUNT, DATATYPE, SOURCE, TAG, COMM, STATUS, IERROR)
        <type> BUF(*)
        INTEGER COUNT, DATATYPE, SOURCE, TAG, COMM, STATUS(MPI_STATUS_SIZE), IERROR

Remarks

The length of the received message must be less than or equal to the length of the receive buffer. This function returns an overflow error if all incoming data does not fit into the receive buffer.

If the received message is shorter than the buffer, only the part of the buffer that corresponds to the message is modified. The remainder of the buffer is not modified.

Processes can send messages to themselves. However, it is unsafe to do so with the blocking send and receive operations, MPI_Send and MPI_Recv, because these blocking send and receive operations can cause a deadlock.

Note

There is an asymmetry between send and receive operations. A receive operation can accept messages from an arbitrary sender, but a send operation must specify a unique receiver. This implements a push style of communication, where data transfer is effected by the sender, rather than a pull style where data transfer is effected by the receiver.

 

Requirements

Product

HPC Pack 2012 MS-MPI Redistributable Package, HPC Pack 2008 R2 MS-MPI Redistributable Package, HPC Pack 2008 MS-MPI Redistributable Package or HPC Pack 2008 Client Utilities

Header

Mpi.h; Mpif.h

Library

Msmpi.lib

DLL

Msmpi.dll

See also

MPI Point to Point Functions

MPI_Send

MPI_Irecv

MPI_Datatype

MPI_Comm

MPI_Status