Instantly share code, notes, and snippets.

Embed
What would you like to do?
co_sum() simple replacement for non-TS18508 compliant compilers (e.g. Intel ifort)
! This code is a simple replacement for basic co_sum() functionality
! https://www.scivision.co/fortran-2018-coarray-quick-start/
! Michael Hirsch, Ph.D.
!
! prereq (Ubuntu >= 17.04 or Debian Stretch 9):
! apt install gfortran libopenmpi-dev libopencoarrays-dev
! or linuxbrew/homebrew
! brew install gcc opencoarrays
!
! compile with:
! gfortran -fcoarray=lib co_sum_ex.f90 -lcaf_mpi
!
! run with mpiexec
!
! complete example: https://github.com/scivision/fortran2018-examples/blob/master/mpi/coarray_pi.f90
program cosubreplace
use, intrinsic:: iso_fortran_env, only: dp=>real64
implicit none
real(dp) :: psum[*] ! [*] declares a coarray, here a scalar
integer :: i
integer, parameter :: N=100 ! arbitrary for your code
! --- example do loop
do i=this_image(), N, num_images()
psum = psum + i**2 ! trivial example
enddo
! ----- alternative workaround for fortran 2018 co_sum()
sync all
if (this_image()==1) then
do i = 2, num_images()
psum = psum + psum[i]
enddo
endif
!------ end co_sum() workaround
end program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment