Fortran

Guide To Learn

Recall from chapter 2 how we declared a regular array:

real, dimension(10) :: a

or, in shorter form:

real :: a(10)

The snippet declares a real array, a, of size 10. The attribute dimension here is key. Declaration of coarrays works the same way, except that you’ll use the attribute codimension instead:

real, codimension[*] :: a

Or shorter:

real :: a[*]

This snippet declares a scalar coarraya, a copy of which will be created on every image that runs the program. For example, on four images, each will have a local instance of a real variable a. Two syntax rules for declaring coarrays stand out:

  1. The codimension attribute uses square brackets, not parentheses. This rule applies to indexing the elements of a coarray, as we’ll see in a bit.
  2. The coarray size, indicated in square brackets, must be *, not any other literal constant or parameter, because the total number of images is determined when loading the program on the OS-level, and not programmatically.

Notice how I emphasized that the most recent snippets declare a scalar coarray, not an array coarray. This may confuse you at first because arrays and coarrays have such similar names. However, it helps to think about coarrays as completely separate entities from arrays that share some of their characteristics. To declare a coarray that’s also an array, combine the rules for declaring each of them:

real, dimension(10), codimension[*] :: a

or, in shorter form:

real :: a(10)[*]

This snippet will declare a real array a with 10 elements on each image.

Declaring coarrays

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top