Can an MPI_WAITALL call be skipped if all requests are already complete?

Let’s say I have an array of non-blocking MPI requests initiated in a series of calls to MPI_ISEND (or MPI_IRECV). I store the request info in the array xfer_rqst. It is my understanding that when a request completes, its corresponding value in xfer_rqst will be set to MPI_REQUEST_NULL. Further, it’s my understanding that if a call is made to MPI_WAITALL, it will have work to do only if some requests in xfer_rqst still have some value other than MPI_REQUEST_NULL. If I have it right, then, if all requests complete before we get to the MPI_WAITALL call, then MPI_WAITALL will be a no-op for all intents and purposes. If I am right about all this (hoo boy), then the following Fortran code should work and maybe occasionally save a useless function call:

IF (ANY(xfer_rqst /= MPI_REQUEST_NULL))       &
            CALL MPI_WAITALL(num_xfers, xfer_rqst, xfer_stat, ierr)

I have actually run this several times without an issue. But still I wonder, is this code proper and safe?

>Solution :

It is indeed often the case that you decide from the structure of your code that certain requests are satisfied. So you think you can skip the wait call.

And indeed you can. The only thing you’re missing is that the wait call deallocates your request object. In other words, by skipping the wait call you have created a memory leak. If your wait call is in a region that gets iterated many times, this is a problem.

In your particular case, I think you’re wrong about the null request: it’s the wait call that sets the request to null. Try it: see if any requests are null before the wait call.

Leave a Reply