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
array[1]%valuesundefined when it's not yet assigned a value? - knia