Bureaucrats, cc_docs_admin, cc_staff
2,879
edits
Line 370: | Line 370: | ||
=== Safe MPI === | === Safe MPI === | ||
The MPI standard defines <tt>MPI_Send</tt> and <tt>MPI_Recv</tt> to be '''blocking calls'''. | The MPI standard defines <tt>MPI_Send</tt> and <tt>MPI_Recv</tt> to be '''blocking calls'''. This means <tt>MPI_Send</tt> will not return until it is safe for the calling module to modify the contents of the provided message buffer. Similarly, <tt>MPI_Recv</tt> will not return until the entire contents of the message are available in the message buffer the caller provides. | ||
It should be obvious that | It should be obvious that whether or not the MPI library provides buffering does not affect receive operations. As soon as the data is received, it will be placed directly in the message buffer provided by the caller and <tt>MPI_Recv</tt> will return; until then the call will be blocked. <tt>MPI_Send</tt> on the other hand need not block if the library provides an internal buffer. Once the message is copied out of the original data location, it is safe for the user to modify that location, so the call can return. This is why our parallel "Hello, world!" program doesn't deadlock as we have implemented it, even though all processes call <tt>MPI_Send</tt> first. Since the buffering is not required by the MPI standard and the correctness of our program relies on it, we refer to such a program as '''''unsafe''''' MPI. | ||
A '''''safe''''' MPI program is one that does not rely on a buffered implementation in order to function correctly. The following pseudo-code fragments illustrate this concept: | A '''''safe''''' MPI program is one that does not rely on a buffered implementation in order to function correctly. The following pseudo-code fragments illustrate this concept: |