# Assigning the same input value to a variable on all coarrays

**URL:** <https://fortran-lang.discourse.group/t/assigning-the-same-input-value-to-a-variable-on-all-coarrays/4536>\
**Category:** Help\
**Created:** [October 15, 2022, 2:06pm UTC](https://fortran-lang.discourse.group/t/assigning-the-same-input-value-to-a-variable-on-all-coarrays/4536 "2022-10-15T14:06:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [October 15, 2022, 2:06pm UTC](https://fortran-lang.discourse.group/t/assigning-the-same-input-value-to-a-variable-on-all-coarrays/4536/1 "2022-10-15T14:06:43Z")

</div>

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 ?

```auto
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

```

---

<div class="post-metadata">

**Author:** ![han190](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/han190/32/7158_2.png) [@han190](https://fortran-lang.discourse.group/u/han190)\
**Post date:** [October 15, 2022, 4:00pm UTC](https://fortran-lang.discourse.group/t/assigning-the-same-input-value-to-a-variable-on-all-coarrays/4536/2 "2022-10-15T16:00:56Z")

</div>

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

```fortran
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

```fortran
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

```

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [October 15, 2022, 4:44pm UTC](https://fortran-lang.discourse.group/t/assigning-the-same-input-value-to-a-variable-on-all-coarrays/4536/3 "2022-10-15T16:44:53Z")

</div>

Thank you !
