Parallelism in the language standard
Coarrays put parallel programming inside the Fortran language itself, introduced in the Fortran 2008 standard and extended in Fortran 2018. Instead of calling an external library to move data between processes, a program uses ordinary array notation — with square brackets — to read and write data that lives on other images. The compiler and runtime handle the communication underneath.
Images and coarray syntax
A coarray program runs as a number of images, each an executing copy of the same program with its own memory. Every image owns its own copy of each coarray variable. A declaration adds a codimension in square brackets after the ordinary dimensions:
real, allocatable :: grid(:,:)[:]
! grid is an allocatable array on every image,
! with a coarray copy reachable from other imagesAn image reads or writes another image's copy by subscripting the codimension: grid(i,j)[p] names the element on image p. Local access needs no brackets at all, so most of the program is written exactly like an ordinary sequential one — a key part of the design.
Synchronization
Images advance independently, so ordering must be stated where it matters. The sync all statement makes an image wait until every image has reached it, and guarantees memory updates are visible across images. The sync images statement synchronizes with a specified list of images, which allows finer-grained coordination. A small set of statements like these carries most of the synchronization load in typical coarray programs.
When coarrays fit
Coarrays suit problems with regular structure: grids and meshes divided across images, where each image mostly computes on its own data and exchanges only its edges with neighbors. For irregular communication patterns, or for coupling with existing message-passing libraries, explicit message passing may be the more direct fit. The two styles can also be combined, with message passing inside a node and coarrays across it.
The companion article Message Passing Concepts covers the other major style.