Skip to content

Instantly share code, notes, and snippets.

@wesbarnett
Created May 23, 2014 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesbarnett/eddebaeaf0fe003455dc to your computer and use it in GitHub Desktop.
Save wesbarnett/eddebaeaf0fe003455dc to your computer and use it in GitHub Desktop.
! Created by Tobias Burnus 2010.
! https://gcc.gnu.org/wiki/CoarrayExample
program Hello_World
implicit none
integer :: i ! Local variable
character(len=20) :: name[*] ! scalar coarray
! Note: "name" is the local variable while "name[<index>]"
! accesses the variable on a remote image
! Interact with the user on Image 1
if (this_image() == 1) then
write(*,'(a)',advance='no') 'Enter your name: '
read(*,'(a)') name
! Distribute information to other images
do i = 2, num_images()
name[i] = name
end do
end if
sync all ! Barrier to make sure the data has arrived
! I/O from all nodes
write(*,'(3a,i0)') 'Hello ',trim(name),' from image ', this_image()
end program Hello_world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment