My following coarray code does not show the expected output
program caftest
implicit none
integer, dimension(5), codimension[*] :: a = 1
! Image 1
a(1)[1] = 11
sync all
! Image 2
a(2)[2] = a(1)[1]
sync all
! Only Image 1 prints
if (this_image() == 1) then
print*, 'a(2)[2] (Image 2 a(2)):', a(2)[2] ! Should be 11
print*, 'a(1)[1] (Image 1 a(1)):', a(1)[1] ! Should be 11
end if
end program
output
a(2)[2] (Image 2 a(2)): 1
a(1)[1] (Image 1 a(1)): 11
However, modifying it provides the expected output
program caftest
implicit none
integer, dimension(5), codimension[*] :: a = 1
! Image 1
if (this_image() == 1) a(1) = 11
sync all
! Image 2
if (this_image() == 2) a(2) = a(1)[1]
sync all
! Only Image 1 prints
if (this_image() == 1) then
print*, 'a(2)[2] (Image 2 a(2)):', a(2)[2] ! Should be 11
print*, 'a(1)[1] (Image 1 a(1)):', a(1)[1] ! Should be 11
end if
end program
output
a(2)[2] (Image 2 a(2)): 11
a(1)[1] (Image 1 a(1)): 11
can’t we use the shorter version (first code) of accessing data among different images? I run the codes windows 10.