NCSA Home
Contact Us | Intranet | Search

ncsa

Point-to-Point Overview

  1. Data Transmissions
    1. MPI_SEND
    2. MPI_RECV
    3. MPI_SENDRECV
    4. MPI_SENDRECV_REPLACE
  2. Parts of an MPI Message
    1. Message Data
    2. Message Envelope


1.0 Data Transmissions

Point-to-point is the basic communication pattern in MPI. As the name implies, point-to-point communications handle data transmission between any two processors in a communicator. Only two processors are involved: one sends the data and the other receives it. Most MPI communications are built around this basic point-to-point communications.

A processor sends data to another processor by calling the MPI function MPI_SEND. The processor receiving the data calls MPI_RECV.

1.1 MPI_SEND

This is the standard MPI function for sending a message. The calling format is:

FORTRAN MPI_SEND(data,count,datatype,dest,tag,comm,ierr)
C MPI_Send(data,count,datatype,dest,tag,comm)

By definition, this call is blocking. It does not return until the data are sent or are copied outside the send buffer. Upon a return from this call, the sender processor can safely modify its send buffer without affecting the data in the message.

1.2 MPI_RECV

The standard MPI_RECV is a blocking receive. The receiver, upon calling MPI_RECV, blocks until the receive buffer is safe to use (i.e., the message has been received).

FORTRAN MPI_RECV(data,count,datatype,source,tag,comm,status,ierr)
C MPI_Recv(data,count,datatype,source,tag,comm,status)

A simple point-to-point example program, called pi.f, calculates the value of pi using point-to-point communications. You can write this program more elegantly using collective communications.

1.3 MPI_SENDRECV

The MPI_SENDRECV function provides an efficient way to handle a common situtation where a processor needs to send data to another processor and receive data from the same processor, or a different one. Calling MPI_SENDRECV is similar to calling MPI_SEND followed by a call to MPI_RECV.

FORTRAN MPI_SENDRECV(sendbuf,sendcount,sendtype,dest, sendtag, recvbuf,recvcount,recvtype,source,recvtag, comm,status,ierr)
C MPI_Sendrecv(sendbuf,sendcount,sendtype,dest, sendtag, recvbuf,recvcount,recvtype,source,recvtag, comm,status)

The send buffer and receive buffer must be separate.

1.4 MPI_SENDRECV_REPLACE

Another version of MPI_SENDRECV that allows the send buffer and recveive buffer to be the same, which in effect replaces the contents of the send buffer by that of the received buffer.

FORTRAN MPI_SENDRECV_REPLACE(buf,count,datatype,dest,sendtag, source,recvtag,comm,status,ierr)
C MPI_Sendrecv_replace(buf,count,datatype,dest,sendtag, source,recvtag,comm,status)

2.0 Parts of an MPI Message

The arguments passed to an MPI function distinguish two parts of an MPI message:
  • message data, which describes the actual data in the message
  • message envelope, which contains extra information to help deliver the message in a SEND and insure it is the right message to receive in a RECV

2.1 Message Data

The first arguments of an MPI function call describe the actual data being passed.

data points to the buffer containing the data to be sent (MPI_SEND) or received (MPI_RECV).

count tells the number of data elements in the message. This is a number of elements not bytes. This hides machine dependency and gives MPI portability dealing with messages across different platforms where the size of a data element can be different from one system to another.

datatype describes the type of data in the message. A type can be any one of MPI predefined data types, or can be a user-defined derived data type. MPI provides a set of predefined data types that cover the basic type in FORTRAN and C programming languages.

2.2 Message Envelope

dest is the message destination, which is the rank of the processor that will receive the message.

source is the rank of the processor providing the message. MPI_Recv will only receive a message coming from rank source, unless the MPI constant MPI_ANY_SOURCE is used for source. In that case, a message coming from any source is received.

tag is an integer that identifies the message. A receiving process will only receive a message if the message tag matches the tag in the MPI_Recv. If the MPI constant MPI_ANY_TAG is used as a tag in MPI_Recv, then the process will accept a message with any tag.

comm is the communicator of the sender and receiver processes.

status is an array in FORTRAN or a data structure in C. The array or data structure is used by MPI_Recv to store information on the received message. If MPI_Recv is using MPI_ANY_TAG and MPI_ANY_SOURCE for tag and source respectively, then status(MPI_TAG) and status(MPI_SOURCE) can be used to find the tag and source of the received message. In C, this is the status.MPI_TAG and status.MPI_SOURCE.