(also posted to comp.lang.fortran).
I'm trying to write a short demo coarray program
illustrating a race condition.
I find that I cannot do it with ifort v.15
because it seems to apply image synchronisation
even when it's not in the code.
Is this an allowed compiler behaviour?
I think probably yes, but wanted to check.
Here's my example:
% cat z.f90
program swap
use iso_fortran_env, only: output_unit
implicit none
integer :: img, i[*]
img = this_image()
i = img
if ( img .eq. 1 ) then
read (*,*)
i = i[ num_images() ]
end if
if ( img .eq. num_images() ) then
i = i[ 1 ]
end if
write (output_unit,*) img, "kuku"
end program swap
% setenv FOR_COARRAY_NUM_IMAGES 4
% ifort -coarray -O0 z.f90
(note the noopt flag)
% ./a.out
2 kuku
3 kuku
At this point the execution is paused
waiting for the user input at READ(*,*).
When I hit ENTER, I get the remaining lines:
1 kuku
4 kuku
So it seems the compiler recognised that
I'm swapping values between 2 images and
synchronised the exectution segments between
images 1 and 4.
Anyway, I just wanted to ask for confirmation
in this list that such compiler behind the
scenes synchronisation does not violate the
standard.
Thanks
Anton
|