This question might be specific to the Intel compiler when using the -parallel
/-Qparallel
option, but I was wondering what happens in the case that two functions on the right hand side write to the same global data.
My minimum working example is:
program test
implicit none
integer :: state, r
state = 0
r = a() - b()
if (r /= 0) error stop 'race condition'
print*, 'all fine'
contains
real function a()
state = 1
a = state*2
end function a
real function b()
state = 2
b = state
end function b
end program test
Note that this is the well behaved case because both functions set the global variable explicitly. It is inspired from FFTW. A more error prone case would be:
program test
implicit none
integer :: state, r
state = 0
r = a() - b()*2
if (r /= 0) error stop 'race condition'
print*, 'all fine'
contains
real function a()
state = 1
a = state * 2
end function a
real function b()
b = state
end function b
end program test