# Coarrays

Coarrays and synchronization constructs are defined by the Fortran 2008 Standard and extended by Fortran 2018. These constructs support parallel programming using a Single Program Multiple Data (SPMD) model. These features are not available on macOS systems.

### Note

Coarrays are only supported on 64-bit architectures.

You must specify compiler option [Q]coarray to enable coarrays in your program.

A Fortran program containing coarrays is interpreted as if it were replicated a fixed number of times and all copies were executed asynchronously.

Each replication is called an "image", and each image has its own set of data objects. The number of images is set at run-time, but it can also be set by a compiler option or an environment variable.

The array syntax of Fortran is extended with additional trailing subscripts in square brackets to provide a clear representation of references to data that is spread across images. References without square brackets are to local data, so source code that can run independently is uncluttered. Any appearance of square brackets indicates communication between images.

A team is an ordered set of images. Each image is identified by a unique image index, numbered from 1 to the number of images on the team. The set of all images at program start up is called the initial team. A team of images can be divided into subteams by executing a FORM TEAM statement. The team executing the FORM TEAM statement is the parent team of th teams created by the FORM TEAM statement. Each child team of a parent team is identified by a team number, which is a positive integer value specified on the FORM TEAM statement. The initial team has no parent team.

While the program is executing, each image executes on a current team. At program start-up, the current team is the initial team, which consists of all images. An image's current team changes when a CHANGE TEAM statement is executed, causing the images of the current team to begin executing as images on subteams of the current team; the subteam an image is on becomes its current team. When an END TEAM statement is executed by an image, the image's current team becomes the team that was current just before the corresponding CHANGE TEAM statement was executed. Image indices are relative to the current team, unless a different team is specified.

Usually, each image resides on one processor. However, several images may share a processor and one image can execute on a cluster.

To reference any array variable that is coindexed, a subscript list must be present. If no subscript list is present, then the coindexed object must be a scalar.

## Examples

Consider the following statement:

    real, dimension(500), codimension[*] :: a,b

This statement declares two objects `a` and `b`, each as a coarray. A coarray always has the same shape on each image. In this case, each image has two real coarrays of size 500.

Consider that an image executes the following statement:

    a(:) = b(:)[q]

In this case, the coarray `b` on image `q` is copied into coarray `a` on the executing image.

Consider the coindexed reference `x[k]`. If `x` is a rank 1 array, this reference to `x` on image `k` is incorrect syntax: a subscript list must be present. The correct form is `x(:)[k]` to access the entire array `x` on image `k`. If `x` is a scalar, then the syntax `x[k]` is correct.

Parent topic: Variables

## See Also

Image Control Statements
Established Coarrays
Using Coarrays