I want to use the fortran coarray feature to have different size arrays on different images.
Following the 2008/2018 standard, this should be possible by using a derived type containing an allocatable. I am using gfortran 8.2.0 with opencoarrays 2.3.1.1 MPI library on macOS Mojave.
program Main
implicit none
type :: Array_Type
double precision, dimension(:), allocatable :: values
end type
type(Array_Type), codimension[*] :: array
if(this_image() == 1) then
allocate(array%values(2))
array%values = this_image()
else
allocate(array%values(1))
endif
sync all
print *, this_image(), array[1]%values(:)
sync all
end program
The program is compiled by
gfortran -Wall -fcoarray=lib Main.f90 -lcaf_mpi
An even simpler example leads to the same segmentation fault when the allocated array is accessed by other images.
program Main
implicit none
type :: Array_Type
double precision, dimension(:), allocatable :: values
end type
type(Array_Type), codimension[*] :: array
allocate(array%values(2))
sync all
print *, this_image(), array[1]%values(:)
sync all
end program
Solution
The code works correctly with the specified system as long as MPICH instead of the default OpenMpi is used with OpenCoarrays.
Additionally, the OpenCoarrays compiler wrapper should be used: caf Main.f90
I opened an issue at the OpenCoarrays GitHub site: https://github.com/sourceryinstitute/OpenCoarrays/issues/625