Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The non-blocking test for available messages is done using the <code>MPI_Iprobe</code> call. In your case it would look like:</p> <pre><code>int available; MPI_Status status; if(rank == 0) // the searching process { for (int i=0; i &lt; 4000000; i++) { // do some stuff here; does not matter what /* see if any message has been transmitted to me at this point without blocking the process; if at this time it happens to be transmitted, do something and than continue with for iternations; or just continue with for iterations and maybe next time will have a message which sends me to do something */ // Tag value 100 matches the value used in the send operation MPI_Iprobe(MPI_ANY_SOURCE, 100, MPI_COMM_WORLD, &amp;available, &amp;status); if (available) { // Message source rank is now available in status.MPI_SOURCE // Receive the message MPI_Recv(..., status.MPI_SOURCE, status.MPI_TAG, MPI_COMM_WORLD, &amp;status); } } } </code></pre> <p><code>MPI_ANY_SOURCE</code> is used as wildcard rank, i.e. it instruct <code>MPI_Irecv</code> to check for messages from any source. If a corresponding send was posted, then <code>available</code> will be set to true, otherwise it will be set to false. The actual source of the message is also written to the <code>MPI_SOURCE</code> field of the status object. If the <code>available</code> flags indicates the availability of a matching message, one should then post a receive operation in order to receive it. It is important that the rank and the tag are explicitly specified in the receive operation, otherwise a different message could get received instead.</p> <p>You could also use persistent connections. These behave very much like non-blocking operations with the important difference that they could be restarted multiple times. The same code with persistent connections would look like:</p> <pre><code>if(rank == 0) // the searching process { MPI_Request req; MPI_Status status; int completed; // Prepare the persistent connection request MPI_Recv_init(buffer, buf_size, buf_type, MPI_ANY_SOURCE, 100, MPI_COMM_WORLD, &amp;req); // Make the request active MPI_Start(&amp;req); for (int i=0; i &lt; 4000000; i++) { // do some stuff here; does not matter what /* see if any message has been transmitted to me at this point without blocking the process; if at this time it happens to be transmitted, do something and than continue with for iternations; or just continue with for iterations and maybe next time will have a message which sends me to do something */ // Non-blocking Test for request completion MPI_Test(&amp;req, &amp;completed, &amp;status); if (completed) { // Message is now in buffer // Process the message // ... // Activate the request again MPI_Start(&amp;req); } } // Cancel and free the request MPI_Cancel(&amp;req); MPI_Request_free(&amp;req); } </code></pre> <p>Persistent operations have a slight performance edge over the non-persistent ones, shown in the previous code sample. It is important that <code>buffer</code> is not accessed while the request is active, i.e. after the call to <code>MPI_Start</code> and before <code>MPI_Test</code> signals completion. Persistent send/receive operations also match non-persistent receive/send operations, therefore it is not necessary to change the code of the workers and they can still use <code>MPI_Isend</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload