Research Article

Using Coarrays to Parallelize Legacy Fortran Applications: Strategy and Case Study

Listing 8

Optimized collective sum routine.
subroutine vector_co_sum_parallel(vector)
real(rkind), intent(inout)  :: vector(:)[*]
real(rkind), allocatable  :: temp(:)
integer image, step
allocate (temp, mold = vector)
 step = 2
do while (step/2 <= num_images())
  sync all
  if (this_image() + step/2 <= num_images()) then
   temp = vector + vector[this_image() + step/2]
  else
   temp = vector
  end if
  sync all
  vector = temp
  step = step * 2
end do
sync all
if (this_image()/ = 1) vector = vector1
sync all
end subroutine