Blocking calls return only when data in message buffer are safe to use
- Send call returns when data can be modified
- Receive call returns when data are updated and valid
A blocking send or receive call suspends execution of the program until the message buffer being sent/received is safe to use. In the case of a blocking send, this means that the data to be sent have been copied out of the send buffer, but they have not necessarily been received in the receiving task. The contents of the send buffer can be modified without affecting the message that was sent. Completion of a blocking receive implies that the data in the receive buffer are valid.
Non-blocking calls just initiate communication; status must be verified later
- Choose MPI_Wait (or variant) (S) to block until safe
- Choose MPI_Test (or variant) (S) to check status prior to an action
Non-blocking calls return immediately after initiating the communication. The programmer does not know at this point whether the data to be sent have been copied out of the send buffer, or whether the data to be received have arrived. So, before using the message buffer, the programmer must check its status. Status will be covered in MPI Point to Point II.
The programmer can choose to block until the message buffer is safe to use, by using a call to MPI_Wait and its variants (S) or to just return the current status of the communication by using MPI_Test and variants (S).
The different variants of the Wait and Test calls allow you to check the status of a specific message, or to check all, any, or some of a list of messages.
Remember to complete all non-blocking send and receive calls in order to free up system resources
It is fairly intuitive why you need to check the status of a non-blocking receive: you do not want to read the message buffer until you are sure that the message has arrived. It is less obvious why you would need to check the status of a non-blocking send. This is most necessary when you have a loop that repeatedly fills the message buffer and sends the message. You can't write anything new into that buffer until you know for sure that the preceding message has been successfully copied out of the buffer. Even if a send buffer is not re-used, it is advantageous to complete the communication, as this releases system resources.