Non-blocking MPI calls in Fortran, safe or not?

Viewed 103

In Using MPI, Gropp et al. give a fairly detailed discussion of using non-blocking MPI sends and receives, and illustrate them with Fortran code. However, in Using Advanced MPI, chapter 11, "Working with Modern Fortran", the same (pretty much) authors warn that Fortran compilers don't really understand non-blocking subroutines and aggressively optimize and so they might optimize code in a way that is erroneous. They then illustrate a semi-portable way of protecting against this.

So I am confused. I have seen a ton of non-blocking MPI operations in Fortran, and have written more than a few myself. And there doesn't seem to be any problem with it. So what is the truth? It's unsafe but many people have just been getting lucky over the years?

UPDATE: In case anyone is interested, I figure "fair usage" allows me to copy the authors' example here:

    Use mpi_f08
    INTEGER :: rbuf(1000000), rval
    TYPE(MPI_Request) :: req
    call MPI_IRECV(rbuf, 1000000, MPI_INTEGER, 0, 0, MPI_COMM_WORLD, req)
    call MPI_WAIT(req, MPI_STATUS_IGNORE)
    rval = rbuf(1)

The authors point out the a particularly aggressive Fortran compiler could, following its own rules, rearrange the last couple of lines to

rval = rbuf(1)
call MPI_WAIT(req, MPI_STATUS_IGNORE)

which could result in a total mess.

0 Answers
Related