Coarray Fortran on LRZ HPC systems

How to compile and run Coarray Fortran programs on LRZ HPC systems

Coarray Fortran

Coarrays are a small extension to Fortran which provide a simple, explicit notation for data decomposition. An updated version of the concept has been incorporated into the Fortran 2008 standard.

Availability on LRZ HPC systems

Coarrays are supported by two compilers on the LRZ HPC systems:

  • Intel's Fortran compiler (ifort) from version 12.0 upwards (x86_64 systems only)
  • The g95 compiler from 0.92 upwards. It requires a commercial add-on to actually run the binaries in parallel, comprised of a special version of the run time library and a parallel console. Alternatively, a shared memory implementation is also available.

Please load the environment module caf, which gives you one of the coarray environments:

module load caf

By default, the Intel compiler's run time is added to the existing fortran/intel module, which must be loaded with a version number of 12.0 or greater

module load caf/g95_cocon

will load the coarray console version, and

module load caf/g95

the shared memory version.

Building and running programs

A simple (and trivial) example program

program hello

  implicit none 

  write(*, '(''Hello from image '',i0, '' of '',i0)') &       


end program

stored in the file hello.f90 can then be compiled with the suitable compiler command, and then executed using multiple cores, one for each image. The following table indicates how this works for the various compilers.


Intel Fortran

(distributed memory)

Intel Fortran

(shared memory)

g95 coarray console

g95 shared memory

Compiling ifort -coarray=distributed -o h.exe hello.f90 ifort -coarray -o h.exe hello.f90 caf -o h.exe hello.f90 g95 -o h.exe hello.f90
Running export FOR_COARRAY_NUM_IMAGES=32

module load




cocon -n -i4 --batch ./h.exe ./h.exe --g95 images=4
Remarks loading the MPI module assures the correct host file is used for batch jobs   caf is a compiler wrapper which eventually executes g95. The -n switch for cocon causes standard output from each image to be prepended by the image index.


cocon can also be used in console mode; please read the file $CAF_DOC for details.



Coarray Documentation

  • Summary of the coarray feature (as covered in the Fortran 2008 standard) by John Reid. Some coarray features not discussed in this paper have been split off and will be reintroduced via a technical specification.
  • Andy Vaught's coarray compendium
  • Intel Fortran compiler documentation for versions 12.0 and higher, available from the LRZ web server or from the Intel web site