Fortran

Guide To Learn

Allocating dynamic coarrays

Like with regular (noncoarray) variables, coarrays can be made allocatable, which is necessary whenever we don’t know the size or shape of the variable at compile time.

For example, you’d declare an allocatable array coarray like this:

real, dimension(:), codimension[:], allocatable :: a

Or, in shorter form:

real, allocatable :: a(:)[:]

The same rules apply as with allocating regular variables. The following snippet will allocate a with 10 elements on each image:

allocate(a(10)[*])

Like any other allocatable variables, coarrays can also be deallocated:

deallocate(a)

This frees the memory used by a on all images.

Synchronization on allocate and deallocate

Allocating or deallocating a coarray always triggers a synchronization of images. Think of it as there always being an implicit sync all anytime you allocate or deallocate a coarray.

Allocating dynamic coarrays

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top