CODIMENSION attribute

Standard: F77 F90 F95 F2003 F2008 Example program


<Syntax>

type, CODIMENSION ‘[’ coarray-spec ‘]’ [ , attr-spec ]... :: decl-list
(The notation ‘[’ and ‘]’ means the actual square bracket characters, i.e. not treating them as BNF optionality brackets.)

CODIMENSION [ :: ] name ‘[’ coarray-spec ‘]’ [ , name ‘[’ coarray-spec ‘]’ ]...

coarray-spec ::= explicit-coshape-spec | deferred-coshape-spec

explicit-coshape-spec ::= [ [ lower-cobound : ] upper-cobound , ]... lower-cobound : *
lower-cobound ::= expression
upper-cobound ::= expression
The cobound expressions must be scalar Integer expressions.

deferred-coshape-spec ::= [ : , ]... :

<Semantics>

The CODIMENSION attribute declares coarrays. A coarray with an explicit-coshape-spec must be a dummy argument or a variable with the SAVE attribute. A coarray with a deferred-coshape-spec must have the ALLOCATABLE attribute; it can be a variable or a component, but not a function result. A coarray cannot be a pointer, and is not allowed to be of type C_PTR or C_FUNPTR from the intrinsic module ISO_C_BINDING.

A variable with a coarray ultimate component must be a dummy argument or have the SAVE attribute. A variable or component that has a coarray ultimate component must be scalar, must not be a pointer or allocatable, and must not itself be a coarray.

The maximum corank of a coarray is 15 minus its rank according to the Fortran standard; the NAG Fortran Compiler supports a maximum corank of 31 minus its rank.

The CODIMENSION attribute can also be specified by putting a coarray-spec in square brackets after the entity name in a type declaration or component definition statement; this overrides any CODIMENSION clause that might be present.

<Execution semantics>

In a coarray program with multiple images, each image has its own separate copy of all variables. Coarray variables however can be accessed directly from another image.

To access another image's copy of a coarray, cosubscripts are used following the coarray name in square brackets; this is called “coindexing”, and such an object is a “coindexed object”. For example, given the declaration REAL,SAVE :: e[*], the coindexed object e[1] refers to the copy of E on image one, and e[13] refers to the copy of E on image 13.

When a coarray is an array, you cannot put the cosubscripts directly after the array name, but must use array section notation instead. For example, with REAL,SAVE :: g(10,10)[*], the reference g[inum] is invalid, to refer to the whole array G on image INUM you need to use g(:,:)[inum] instead.

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.

<Related>

Component Definition statement, Image control statements, Image selectors, LCOBOUND intrinsic function, Type Declaration statement, UCOBOUND intrinsic function,