Coarray* support in gfortran as specified in the Fortran 2008 standard
Coarrays are also known as CAF = Co(-)Array Fortran
Coarray Fortran enables a programmer 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 http://users.physik.fu-berlin.de/~tburnus/coarray/README.txt (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 = 5 A = 7
which writes "5" to the scalar coarray "A" on the (remote) image corresponding to the cosubscript  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,
SYNC IMAGES(<scalar image index, array with image indexes or "*">)
or blocks which ensure that instructions are only executed on one image at a time
CRITICAL; ...; END CRITICAL
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
Fortran 2008 [Final Draft International Standard (FDIS)], ftp://ftp.nag.co.uk/sc22wg5/N1801-N1850/N1830.pdf
Coarrays in the next Fortran Standard by John Reid, ftp://ftp.nag.co.uk/sc22wg5/N1801-N1850/N1824.pdf
Rational for Co-Arrays in Fortran 2008 by Aleksandar Donev, ftp://ftp.nag.co.uk/sc22wg5/N1701-N1750/N1702.pdf
Draft Technical Specification (TS) 18508 on Additional Parallel Features in Fortran draft)|N2027]] (22 August 2014)
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.
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:
- Issues with nonallocatable polymorphic coarrays dummy argument and SELECT CLASS and ASSOCIATE
- Possible issues with numeric-type conversion in coindexed assignments (possibly only testcase/verification missing)
- Vector subscript support is lacking in the library (but not in the compiler)
Support for allocatable and pointer components of coarrays. (Only when remote access is involved; the compiler gives an error in that case.)
Issues with nonallocatable/nonpointer components of derived-type coarrays, especially when the derived type is an array coarray; in particular array access of the form caf(:)[i]%sub requires the new array descriptor
CO_BROADCAST and CO_REDUCE do not do finalization and don't handle allocatable components
Handling of type(lock_type) components in derived types or as CLASS (currently rejected at compile time).
- All of TS18508 features are not yet implemented -- except for the already supported collectives and new atomic intrinsics
- Improved run-time diagnostic support
- Documentation of the library API
- Asynchronous support and coarray-aware compile-time optimizations
- Review of the ABI/API.
- Note that the multi-image communication library might have additional issues.
For single-image (serial) programs: Simply add the flag -fcoarray=single and compile, link and run as usual.
For multi-image programs: See library-based coarray documentation