I think this program is conforming:
program mumu
use, intrinsic :: iso_fortran_env
implicit none
integer( atomic_int_kind ) :: z[*]
integer :: p, q, var
p = 1
q = num_images()
z = 0
if ( this_image() .eq. p .or. this_image() .eq. q ) &
write (*,*) "before: img:", this_image(), "z:", z
if ( this_image() .eq. p ) call atomic_define( z[q], 1 )
if ( this_image() .eq. q ) then
do
call atomic_ref( var, z )
if ( var .eq. 1 ) exit
end do
write (*,*) "got it, img:", this_image(), "var:", var, "z:", z
end if
if ( this_image() .eq. p .or. this_image() .eq. q ) &
write (*,*) "after: img:", this_image(), "z:", z
end program mumu
This is adapted from example in MFE, p. 416.
Coarray z is defined on P and referenced on Q in
unordered segments (there is only a single segment
on each image, therefore unordered).
I think 8.5.2 par 3 makes this code conforming:
*quote*
A coarray may be referenced or defined by execution
of an atomic subroutine during the execution of a segment
that is unordered relative to the execution of a segment
in which the coarray is referenced or defined by execution
of an atomic subroutine.
*end quote*
If the code is conforming, then what should be the
correct answer?
One compiler gives this on 16 images:
before: img: 1 z: 0
before: img: 16 z: 0
after: img: 1 z: 0
got it, img: 16 var: 1 z: 1
after: img: 16 z: 1
which is correct, I think.
Another compiler gives this on 24 images:
before: img: 24 z: 0
before: img: 1 z: 0
got it, img: 24 var: 1 z: 0
after: img: 24 z: 0
after: img: 1 z: 0
which is wrong, I think. On image 24 var must
be of the same value as z.
Please comment
Anton
|