Home High Performance Computing MPI Send and Recieve

MPI Send and Recieve

MPI supports messages passing between a source and a destination using two communication primitive: send and receive.

MPI supports the following types of send and receives functions:

  1. Blocking send & Recieve
  2. Non-blocking send & Recieve

1) Blocking Communication – In blocking communication the caller will block or wait until the message is not transmitted to the other end i.e.,  a program that invokes a blocking send primitive will block until the message is received by the destination and a program that invokes a blocking receive primitive will block until a message is received by the caller.

MPI_Send(
    void* buff,
    int count,
    MPI_Datatype datatype,
    int destination,
    int tag,
    MPI_Comm communicator)
MPI_Recv(
    void* buff,
    int count,
    MPI_Datatype datatype,
    int source,
    int tag,
    MPI_Comm communicator,
    MPI_Status* status)
    1. Buffer: It represents the memory location where the message is stored.
    2. Data Count: Count of the number of items of particular MPI datatype(MPI_Datatype).
    3. Datatype: These are MPI predefined datatypes like MPI_CHAR, MPI_INT, etc. MPI datatypes are architecture Independent and hence are portable. Read more…
    4. Destination: The process where a message should be delivered. Specified as the rank of the receiving process.
    5. Source: The rank of originating process of the message or rank of the sending process.
    6. Tag: A random non-negative integer assigned to uniquely identify a message. The tag value of send and receive operation must be the same. If we want to receive any message we need to assign MPI_ANY_TAG as a tag value.
    7. Communicator: A set of processes for which the source or destination fields are valid. Most of the time predefined MPI_COMM_WORLD communicator is used.
    8. Status: Status variable tells the information about the received message e.g.,
      1. status.MPI_TAG: The tag of the received message.
      2. status.MPI_SOURCE: The rank of sending process of the message.

2) Non-Blocking Communication – In non-blocking communication, the caller will not block or wait for the entire message to be transmitted to the other end instead it will terminate and the program will continue. The reason for providing Non-blocking send and receive operations is to allow the process to do something else while waiting for the message to be transmitted or for some message to arrive.

MPI_ISend(
    void* buff,
    int count,
    MPI_Datatype datatype,
    int destination,
    int tag,
    MPI_Comm communicator)
MPI_IRecv(
    void* buff,
    int count,
    MPI_Datatype datatype,
    int source,
    int tag,
    MPI_Comm communicator,
    MPI_Status* status)

MPI also supports some other type of send and receive routines such as Synchronous Send MPI_Ssend (&buf, count, datatype, dest, tag, comm) , Buffered Send  MPI_Bsend (&buf, count, datatype, dest, tag, comm) , Combined send/receive  MPI_Sendrecv(&send_buf, send_ count, send_datatype, dest, send_tag, &recvbuf, recv_count, recv_datatype, source, recv_tag, comm, &status) .


Did, we miss something or do you want to add some other key points?🤔
Please comment. 😊

Subscribe to our weekly newsletter

Join our community of 1000+ developers and stay updated with the fast moving world of computer science

We promise, we won't spam
Even we hate spam as much as you hate them

LEAVE A REPLY

Please enter your comment!
Please enter your name here