!Robert W. Numrich, Introduction to Co-Array Fortran
! http://www2.hpcl.gwu.edu/pgas09/tutorials/caf_tut.pdf
!
subroutine globalSum(x)!
real(kind=8),codimension[0:*] :: x! Fixed, was: "dimension[0:*]"
real(kind=8) :: work!
integer n,bit,i,mypal,dim,me, m!
dim = floor(log(num_images()*1.0)) ! Fixed. Was: log2_images()
if(dim .eq. 0) return!
m = 2**dim!
bit = 1!
me = this_image(x,1)!
do i=1,dim!
mypal=xor(me,bit)!
bit=shiftl(bit,1)!
sync all!
work = x[mypal]!
sync all!
x=x+work!
end do!
end subroutine globalSum
