Image selectors

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


The syntax for designating a variable has been extended by the addition of “image selectors”. A variable designated with an image selector is a “coindexed object”.

An image selector appears after a coarray name as follows:

coarray-name [ ( section-subscript-list ) ] [ image-selector ]

image-selector ::= '[' cosubscript-list [ , image-selector-spec ]... ']'

The notation '[' and ']' indicates that the square brackets themselves appear in the program, i.e. these square brackets are not BNF optionality specifiers.

cosubscript-list ::= expression [ , expression ]...

The number of expressions in the cosubscript-list must be equal to the “corank” (number of codimensions) of the coarray. The cosubscript expressions must be scalar and of type Integer.

image-selector-spec ::= STAT = stat-variable
| TEAM = expression
| TEAM_NUMBER = expression

The stat-variable must be a non-coindexed scalar Integer variable, and should be capable of representing the values −9999 to +9999. The expression in a TEAM= specifier must be a non-coindexed scalar value of type TEAM_TYPE from the intrinsic module ISO_FORTRAN_ENV. The expression in a TEAM_NUMBER= specifier must be a scalar Integer value.

For a substring of a coindexed object of type Character, the substring notation follows the image selector.

The same syntax is used for a coarray name that is a component, and a coarray name that is a variable. If the coarray is also an array, section-subscript-list is required: that is, the usual practice of selecting a whole array simply by using the array name cannot be used for coindexed objects.

Note that restrictions on declaring coarrays means that at most one of the variable name and component names in a designator can be a coarray, and therefore at most one image-selector can appear in a variable designator.


In a coarray program with multiple images, the image selector on a coarray selects the image on which to access the coarray. The image number is calculated from the cosubscripts in the same way that the subscripts of an array determine the array element number.

If the selected image has failed, assignment to the coindexed object is ineffective, and reading the value of the coindexed object returns an unpredictable result; if the STAT= specifier appears, the value of STAT_FAILED_IMAGE from the intrinsic module ISO_FORTRAN_ENV is assigned to stat-variable. If the STAT= specifier appears and the selected image has not failed, the value zero is assigned to the stat-variable.

Except when using atomic subroutines, writing to a coarray from one image while reading (or writing) from another image is only permitted in “ordered” execution segments. Image control statements provide mechanisms for defining execution segments and synchronising them between images.


ATOMIC_ADD intrinsic subroutine, ATOMIC_AND intrinsic subroutine, ATOMIC_CAS intrinsic subroutine, ATOMIC_DEFINE intrinsic subroutine, ATOMIC_OR intrinsic subroutine, ATOMIC_REF intrinsic subroutine, ATOMIC_XOR intrinsic subroutine, CODIMENSION attribute, Image control statements