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
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:
use, intrinsic :: iso_fortran_env
integer :: n[*], nimgs, i_, me, iu = 100
me = this_image()
nimgs = num_images()
write(*, *) ' Hello from image : ', me, ' of ', nimgs
! 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 !<--- NOTE: equivalent "read(iu, *) n"
write(*, *) ' Image ', me, ' reading file... ok.'
sync all !<-- in the meantime, the others wait for image 1 to finish its work.
n[me] = n + 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]
Hope this helps.