title: Have to MPI_Iprobe several times before receiving messages
body: <p>The application I'm working on involves multiple processes all working on similar tasks, and only occasionally sharing information. I have a working implementation using openMPI, but I'm having issues with messages sometimes being received much later than they are sent.</p>
  
  <p>At the moment, the main loop of each process begins by processing any waiting messages, then does a whole bunch of computation, then sends the results to each of the other processes using MPI_ISend. Something like:</p>
  
  <pre><code>while problem is unsolved:
    bool flag;
    MPI_Iprobe(MPI_ANY_SOURCE, ..., &amp;flag, MPI_IGNORE_STATUS);
    while flag:
      MPI_Recv(&amp;message, ...);
      // update local information based on message contents
      MPI_Iprobe(MPI_ANY_SOURCE, ..., &amp;flag, MPI_IGNORE_STATUS);
  
    result = doComputation(); // between 2s and 1m
  
    MPI_Request request;
    for dest in other_processes:
      MPI_Isend(result, ..., dest, &amp;request);
      MPI_Wait(&amp;request, MPI_STATUS_IGNORE); // Doesn't seem to make any difference 
  </code></pre>
  
  <p>This works OK, but the following problem often occurs: Process X sends a message, but the next time Process Y probes, it finds no message. Often it is only one or two loops (and many seconds) later that Process Y gets the message sent by Process X. The messages always get through eventually, but Process Y shouldn't have to wait until the second or third time it probes to actually receive the message.</p>
  
  <p>I don't have a solid understanding of how MPI works, but from reading other questions I think the problem has something to do with MPI not having a chance to progress the message, because in my program the MPI functions are only called very occasionally, rather than within a tight loop. Trying to give MPI some extra time to progress, I added a few dummy calls to Iprobe:</p>
  
  <pre><code>bool flag;
  MPI_Iprobe(MPI_ANY_SOURCE, ..., &amp;flag, MPI_IGNORE_STATUS);
  MPI_Iprobe(MPI_ANY_SOURCE, ..., &amp;flag, MPI_IGNORE_STATUS);
  MPI_Iprobe(MPI_ANY_SOURCE, ..., &amp;flag, MPI_IGNORE_STATUS);
  MPI_Iprobe(MPI_ANY_SOURCE, ..., &amp;flag, MPI_IGNORE_STATUS);
  while flag:
    MPI_Recv(&amp;message, ...);
    // update local information based on message contents
    MPI_Iprobe(MPI_ANY_SOURCE, ..., &amp;flag, MPI_IGNORE_STATUS);
  </code></pre>
  
  <p>And it works - any sent messages are always received the very next time a process probes for them.</p>
  
  <p>But this is ugly and I suspect it may give different results on different platforms. So is there an alternate way to allow MPI some time to complete message progression before probing? I don't want to use blocking receive without probing because Process Y should be able to continue computation when there are no messages waiting.</p>
  
  <p>Thanks.</p>