Hi @apoorv01 ,
It’s a bit unclear what you mean with these statements.
Maybe, a clarification would further help readers understanding your problem and possibly provide ad-hoc solutions for them.
In the meantime, I tried your code, and by anticipating that I might have not caught what you actually want to achieve with it, I think there are some tiny logic flaws, specially with the loop
do q = 2,pro
n[q]=n[1]
end do
Here and here some references where you can read more about coarrays and how they work in practice. For sure, other more experianced members here can guide you towards more insightful places.
In the meantime, I give you a modified version of your code based on what I thought you are trying to attempt:
program test
use, intrinsic :: iso_fortran_env
implicit none
integer :: n[*], nimgs, i_, me, iu = 100
me = this_image()
nimgs = num_images()
write(*, *) ' Hello from image : ', me, ' of ', nimgs
sync all
! Read file only from image 1
if (me == 1) then
write(*, *) ' Image ', me, ' reading file...'
open(unit=iu, file='xy.txt', form='formatted', action = 'read')
read(iu, *) n[1] !<--- NOTE: equivalent "read(iu, *) n"
close(iu)
write(*, *) ' Image ', me, ' reading file... ok.'
endif
sync all !<-- in the meantime, the others wait for image 1 to finish its work.
n[me] = n[1] + me !<-- Broadcast read value to all other images (1-myself included)
! print results
do i_ = 1, nimgs
if (me == i_) write(*, *) ' Image ', me, ' : n[me] = ', n[me]
sync all
enddo
end program
Hope this helps.
Regards.