I’ve noticed that, while using the OpenCoarray Coarray Fortran Compiler, adding integers, which come from other images, yields incorrect results. Here’s my simple program:
program enigma2
use iso_fortran_env
implicit none
integer, codimension[*], save :: imc
integer :: r
imc = 0
if (.true.) then
imc = 1
end if
sync all
if (this_image() == 1) then
do r = 2,num_images()
print *, r, ': ', imc, ' and ', imc[r]
imc = imc[r] + imc
end do
end if
sync all
print *, 'inc is ', imc
end program enigma2
Here are the results that are given, after running the program:
evansste@Computer5:$ cafrun -np 5 enigma2
2 : 1 and 1
3 : 2 and 2
4 : 4 and 4
5 : 8 and 1
inc is 9
inc is 1
inc is 1
inc is 1
inc is 1
Shouldn’t the resulting total for inc
be equal to the number of images that are used while running this program; which, in this case, is five?
I’m not an expert on Fortran or coarrays. So, I want to make sure I’m not making some silly mistake in how I’ve written this program. Am I doing this right, or is there something wrong with my software installation?
I appreciate any insight that anyone is willing to provide.