[Mpi-comments] MPI 4.0 and Fortran about the Problem with Code Movement and MPI_F_SYNC_REG (section 19.1.17)

Rolf Rabenseifner rabenseifner at hlrs.de
Thu Aug 19 05:52:20 CDT 2021


Dear Dimitri,

> I 've a question about the use of MPI_F_SYNC_REG to avoid optimisation
> problem.
> 
> If I understand well a way to avoid  change in order is to use
> MPI_F_SYNC_REG after the wait like this :
 
    <type>, ASYNCHRONOUS :: buf   ! this is also needed!!! 

>   call MPI_ISEND(buf,...,req)
>   ! some work
>   call MPI_WAIT(req,...)
>   if (.not. MPI_ASYNC_PROTECTS_NONBLOCKING) call MPI_F_SYNC_REG(buf)
>   buf = val2

Only half correct, because the ASYNCHRONOUS declaration was missing.
I added it.
You are allowed to add "ASYNCHRONOUS" in the unit where it is relevant.

> My question is what in this solution prevent the compiler to put the
> "call MPI_WAIT" after the line "buf = val2" ?

If your compiler supports Fortran TS29113 then your compiler  
move accesses to the ASYNCHRONOUS buf across subroutine calls.
In that case, your MPI library (if compiled for that compiler)
should set MPI_ASYNC_PROTECTS_NONBLOCKING = .TRUE.
and therefore the additional call MPI_F_SYNC_REG(buf)
is already removed at compile time.

If your compiler does not support Fortran TS29113 then
your MPI library (if compiled for that compiler)
must set MPI_ASYNC_PROTECTS_NONBLOCKING = .FALSE.
and the "if (.not. MPI_ASYNC_PROTECTS_NONBLOCKING)" 
testing is removed at compile time and the 
"call MPI_F_SYNC_REG(buf)" is always done.

In general, the compiler must not 
 - change the sequence of library calls that it cannot analyze,
 - and must not move the assignment of "buf = val2" across
   a subroutine call with this buf in the argument list,
   again provided the compiler cannot analyze what MPI_F_SYNC_REG is doing.

Based on these two rules together, the MPI_WAIT call and the assignment cannot be interchanged.

I hope this answers your question.

For more details about MPI and Fortran, you may look at 
course chapter 4 and 5 in my MPI-4.0 course:
 https://www.hlrs.de/training/par-prog-ws/MPI-course-material

Best regards
Rolf 

----- Original Message -----
> From: "Comments on the MPI Standard" <mpi-comments at lists.mpi-forum.org>
> To: "Comments on the MPI Standard" <mpi-comments at lists.mpi-forum.org>
> Cc: "Dimitri Lecas" <dimitri.lecas at idris.fr>
> Sent: Thursday, August 19, 2021 11:07:17 AM
> Subject: [Mpi-comments] MPI 4.0 and Fortran about the Problem with Code Movement and MPI_F_SYNC_REG (section 19.1.17)

> Hello,
> 
> I 've a question about the use of MPI_F_SYNC_REG to avoid optimisation
> problem.
> 
> If I understand well a way to avoid  change in order is to use
> MPI_F_SYNC_REG after the wait like this :
> 
> 
>   call MPI_ISEND(buf,...,req)
>   ! some work
>   call MPI_WAIT(req,...)
>   if (.not. MPI_ASYNC_PROTECTS_NONBLOCKING) call MPI_F_SYNC_REG(buf)
>   buf = val2
> 
> 
> My question is what in this solution prevent the compiler to put the
> "call MPI_WAIT" after the line "buf = val2" ?
> 
> 
> Regards
> 
> _______________________________________________
> mpi-comments mailing list
> mpi-comments at lists.mpi-forum.org
> https://lists.mpi-forum.org/mailman/listinfo/mpi-comments

-- 
Dr. Rolf Rabenseifner . . . . . . . . . .. email rabenseifner at hlrs.de .
High Performance Computing Center (HLRS) . phone ++49(0)711/685-65530 .
University of Stuttgart . . . . . . . . .. fax ++49(0)711 / 685-65832 .
Head of Dpmt Parallel Computing . . . www.hlrs.de/people/rabenseifner .
Nobelstr. 19, D-70550 Stuttgart, Germany . . . . (Office: Room 1.307) .


More information about the mpi-comments mailing list