[J3] Question: Aliasing in Parallel Procedure Instances in OpenMP Parallel Regions

Jeff Hammond jehammond at nvidia.com
Sat Feb 10 16:40:34 UTC 2024


Except for omp_get_thread_num(), OpenMP is invisible to the consideration of Fortran compliance in that program, because the directives are only comments.

When you activate OpenMP in a Fortran compiler, you willfully step outside of the Fortran standard and enter the domain language defined by the OpenMP extensions to the Fortran language implemented by your compiler.  You cannot reason about what OpenMP semantics due to a Fortran program from the Fortran standard alone, unless you ignore OpenMP altogether, because OpenMP is not Fortran.

If the OpenMP extensions to the Fortran language define the below program, then it is defined.  If you were to write it with DO CONCURRENT, then you could employ the Fortran specification to reason about it, and in the translation I imagine for that, it is not a legal program because of the data race.  The equivalent coarray program is straightforward to write in a correct way.

Jeff

From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Klemm, Michael via J3 <j3 at mailman.j3-fortran.org>
Date: Saturday, 10. February 2024 at 17.51
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Klemm, Michael <Michael.Klemm at amd.com>
Subject: [J3] Question: Aliasing in Parallel Procedure Instances in OpenMP Parallel Regions
External email: Use caution opening links or attachments


[Public]

Hi folks,

In the OpenMP Language Committee at discussion happened about the below piece of Fortran code.  There was some dissent in the discussion, so I'm hoping for some clarification.

In the example, someone spawns a few threads and calls a Fortran procedure, passing along a variable that's shared in the parallel region.  We understand that dummy arguments cannot alias.  But what about the "variable" dummy argument that aliases in two parallel instances of the same procedure?  It seems that the wording of the aliasing rule does not define that at all (which is not surprising, given that Fortran does not know threads).

So, the question is: Are we in UB land with the below example?  Does the definition of dummy-argument aliasing in Fortran extend to the parallel case, too?

Kind regards,
        -michael


subroutine test(variable)
  use omp_lib, only : omp_get_thread_num
  implicit none
  integer :: variable

  !$omp single
  variable = 1234
  !$omp end single

  if (variable .ne. 1234) then
    print '(A,I0,A,I0)', "ERROR: variable=", variable, ", TID=",omp_get_thread_num()
  endif
end subroutine test

program main
  implicit none
  integer :: variable2

  interface
     subroutine test(variable)
       implicit none
       integer :: variable
     end subroutine test
  end interface

  variable2 = -42
  !$omp parallel shared(variable2)
  call test(variable2)
  !$omp end parallel
end program main
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240210/885ab02f/attachment.htm>


More information about the J3 mailing list