A message consists of the data and the message envelope. The envelope provides information
on how to match sends to receives. The three parameters used to specify the message
envelope are:
Destination or source
This argument is set to a rank in a communicator (see below). Rank ranges from 0
to (size-1) where size is the number of processes in the communicator.
Destination is specified by the send and is used to route the message to the appropriate
process. Source is specified by the receive. Only messages coming from that source
can be accepted by the receive call, but the receive can set source to MPI_ANY_SOURCE
to indicate that any source is acceptable.
Tag
An arbitrary number to help distinguish among messages. The tags specified by the
sender and receiver must match, but the receiver can specify MPI_ANY_TAG to indicate
that any tag is acceptable.
Communicator
The communicator specified by the send must equal that specified by the receive.
Communicators will be described in more depth later in this module.
For now, it is enough to know that a communicator defines a communication
"universe", and that processes may belong to more than one communicator. In this
module, we will only be working with the predefined communicator MPI_COMM_WORLD
which includes all processes in the application.
An Analogy
To help understand the message envelope parameters, consider the analogy of a bill
collection agency that collects for several utilities. When sending a bill the agency
must specify:
- The person receiving the bill (more specifically, their ID number). This is the
destination.
- What month the bill covers. Since the person will get twelve bills each year,
they need to know which month this bill covers. This is the tag.
- Which utility is being collected for. The person needs to know whether this is their
electric or phone bill. This is the communicator.