Coarray* support in gfortran as specified in the Fortran 2008 standard

Coarrays are also known as CAF = Co(-)array Fortran

Coarrays are an extension of Fortran, which allows to write parallel programs using a Partitioned Global Address Space (PGAS) following the SPMD (single program, multiple data) parallelization scheme. Each process (called image) has its own private variables. Variables which have a so-called codimension are addressable from other images. This extension is part of the Fortran 2008 standard (ISO/IEC 1539-1:2010). Technical Specification (TS) 18508 enhances the coarray support (ISO/IEC NP TS 18508; draft)

See also (outdated)

Coarray Syntax and Further Reading

The crucial ingredient are coarrays, which are variables which are visible on all images and have a codimension. They are declared using for instance

  CODIMENSION[1:4,5,*] :: variable

where the highest subscript needs to be a "*" (unless the variable is allocatable - in this case, as usual, only ":" have to be used). A remote coarray can be accessed using the bracket syntax, e.g.

  A[4] = 5
  A = 7

which writes "5" to the scalar coarray "A" on the (remote) image corresponding to the cosubscript [4] and "7" to the local coarray of the executing image. Note that only a single image can be addressed at a given time; e.g. simultaneously broadcasting to collecting from all images is not supported (as of Fortran 2008).

The image index can be obtained using the this_image() intrinsic, the total number of images with num_images(). If an instruction should only be performed on a single image, an explicit

  if(this_image() == ...) then; ...; end if

has to be used.

Besides the coarrays themselves, there exist also image control statements such as for barriers,

or blocks which ensure that instructions are only executed on one image at a time

Note that the STOP statements only terminates one image; if all images should be stopped because of an error use ERROR STOP.

More details can be found in

Historic note: Co-Array Fortran (CAF) has been developed in the 1990s by Robert Numrich and John Reid; it has been implemented as non-standard extension in some compilers (e.g. Cray [since version 3.1] or Rice). When coarrays were incorporated in the Fortran 2008 standard, the term coarrays did not not only loose its hyphen, but also some syntax was changed (e.g. SYNC ALL is now a statement instead of a subroutine). The last change was the renaming of ALL STOP to ERROR STOP in February 2010. Some functionality was removed when CAF were added to Fortran 2008 and has been deferred into a to-be-written Technical Report [now known as Technical Specification (TS) 18508]; this includes collective operations.


Coarray examples can be found on an extra page; see also the test cases included in the compiler (gcc/testsuite/gfortran.dg/coarray_* and gcc/testsuite/gfortran.dg/coarray/*).

Implementation Status in GCC Fortran

GCC 4.6: Only single-image support (i.e. num_images() == 1) but many features did not work.

GCC 4.7: Also multi-image support via a communication library. Comprehensive support for a single image, but most features do not yet work with num_images() > 1

GCC 5: Full support of Fortran 2008 coarrays and of the broadcast/reduction collectives and atomics of TS18508 - except of bugs and incomplete support of special cases. Note that the included communication library currently only handles a single image, but the OpenCoarrays project provides an MPI-based and a GASNet-based communication library. See also CoarrayLib. For caveats see also the next section.

TODO for GCC 5 as of April 2015

Note: With -fcoarray=single, all of Fortran 2008 should be fully supported. Still unsupported or with issues:


None: Coarray (last edited 2015-04-10 12:08:16 by TobiasBurnus)