Assigning the same input value to a variable on all coarrays

Hi,
I am experimenting with coarrays by writing simple toy programs in order to understand coarrays better.
In this program I want to read an input from the user which is an integer and send it to all the images.

However only image one receives it . How can I make it so that all images receive the input ?

PROGRAM coarray_exp1
  IMPLICIT NONE

  ! This program tests how to split a do loop between images

  INTEGER :: i,num[*],lower_halo,upper_halo
  REAL :: full_sum, partial_sum[*]

  IF (NUM_IMAGES() .EQ. 1) THEN
     ERROR STOP "This needs to run on 2 images or more."
  END IF

  If (THIS_IMAGE() .EQ. 1) THEN
     PRINT *, "Enter the numbers you want added up, please: "
     READ *, num
  END If

  SYNC ALL
  PRINT *, "From",THIS_IMAGE(),num[THIS_image()]," was recieved"



END PROGRAM coarray_exp1

Well, num[this_image()] is equivalent to num. Other than that, all you need is num = num[1] after sync all

program main
implicit none

integer :: num[*]

if (this_image() == 1) then
  print *, "enter the numbers you want added up, please: "
  read *, num
end if
sync all
num = num[1]
print *, "from", this_image(), num, " was recieved"

end program main

Also, if you just want to broadcast an integer to all other images, you don’t even need the coindex

program main
implicit none

integer :: num

if (this_image() == 1) then
  print *, "enter the numbers you want added up, please: "
  read *, num
end if
sync all
call co_broadcast(num, 1)
print *, "from", this_image(), num, " was recieved"

end program main
2 Likes

Thank you !