CH 6
CH 6
P0 P1
for (i = 0; i < 1000; i++){ for (i = 0; i < 1000; i++){
produce_data(&a); receive(&a, 1, 0);
send(&a, 1, 1); consume_data(&a);
} }
P0 P1
receive(&a, 1, 1); receive(&a, 1, 0);
send(&b, 1, 1); send(&b, 1, 0);
Non-Blocking
Message Passing Operations
• The programmer must ensure semantics of the send and
receive.
• This class of non-blocking protocols returns from the
send or receive operation before it is semantically safe to
do so.
• Non-blocking operations are generally accompanied by a
check-status operation.
• When used correctly, these primitives are capable of
overlapping communication overheads with useful
computations.
• Message passing libraries typically provide both blocking
and non-blocking primitives.
Non-Blocking
Message Passing Operations
• The basic functions for sending and receiving messages in MPI are
the MPI_Send and MPI_Recv, respectively.
• The calling sequences of these routines are as follows:
int MPI_Send(void *buf, int count, MPI_Datatype
datatype, int dest, int tag, MPI_Comm comm)
int MPI_Recv(void *buf, int count, MPI_Datatype
datatype, int source, int tag, MPI_Comm comm,
MPI_Status *status)
• MPI provides equivalent datatypes for all C datatypes. This is done
for portability reasons.
• The datatype MPI_BYTE corresponds to a byte (8 bits) and
MPI_PACKED corresponds to a collection of data items that has been
created by packing non-contiguous data.
• The message-tag can take values ranging from zero up to the MPI
defined constant MPI_TAG_UB.
MPI Datatypes
MPI Datatype C Datatype
MPI_CHAR signed char
MPI_SHORT signed short int
MPI_INT signed int
MPI_LONG signed long int
MPI_UNSIGNED_CHAR unsigned char
MPI_UNSIGNED_SHORT unsigned short int
MPI_UNSIGNED unsigned int
MPI_UNSIGNED_LONG unsigned long int
MPI_FLOAT float
MPI_DOUBLE double
MPI_LONG_DOUBLE long double
MPI_BYTE
MPI_PACKED
Sending and Receiving Messages