Basic Send and Receive
Objectives
We would like to :
- Understand the basics of sending and receiving messages in MPI
Notes
- Gather/Scatter/Broadcast is one way to communicate
- Point to point messages are another.
- For this session
- First EVERY SEND MUST HAVE A RECEIVE and EVERY RECEIVE MUST HAVE A SEND.
- tag
- When sending/receiving message there is a tag field.
- This is an int.
- This is used to indicate the contents of a message.
- MPI_ANY_TAG
-
int MPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
- buf, count, datatype: as before
- dest: the id of the process we are sending to, but less than the size of the communicator
- tag: as above
- comm: the communications group
-
int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
- buf, count, datatype: as before
- But the buf needs to be big enough to hold any that might be sent.
- as indicated by count
- You might not get this many.
- source: where we expect the message to come from or MPI_ANY_SOURCE
- tag: as above
- comm: the communicator
- status: the result of the communication
- Contains at least:
- MPI_Source : an int, the source of the sender
- MPI_TAG: the tag of the message
- MPI_Error: an error indicator
- There might be additional implementation dependent fields
-
int MPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status *status)
- Check on the next message in the queue that matches the conditions.
- source: an individual or MPI_ANY_SOURCE
- tag: an individual or MPI_ANY_TAG
- comm: the comm group.
- status: the return value of the message.
- Look at the fields to see what message is waiting.
-
https://www.mpich.org/static/docs/v4.1/www3/MPI_Get_count.html
- I will not use today,
- But this will tell you how many of the datatype was received in the message.
- Play a game of toss the ball between members of a computation.