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 the following compilers on the LRZ HPC systems:

  • Intel's Fortran compiler (ifort)
  • GCC's gfortran compiler, beginning with version 5.1

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.

module load caf/gfortran

will load the gfortran implementation. The latter has additional prerequisites, which will be pointed out when you try to load the module.

Building and running programs

A 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 and subsequently executed, typically using multiple cores, at least one for each image. The following table indicates how this works for the various compilers.


Intel Fortran

(distributed memory)

Intel Fortran

(shared memory)


Compiling ifort -coarray=distributed -o h.exe hello.f90 ifort -coarray -o h.exe hello.f90 gfortran -fcoarray=lib -o h.exe hello.f90 $CAF_LIB $MPI_LIB
Running export FOR_COARRAY_CONFIG_FILE=./caf.conf

# may need to unload other MPI before

module load




module load

mpiexec -n 4 ./h.exe


The configuration file pointed at by FOR_COARRAY_CONFIG_FILE is described in a separate section below.


The mpiexec command from the currently loaded MPI module is used for startup. The same MPI module should be used for compilation and execution.

 Intel Fortran configuration file

For startup of distributed memory coarray programs a configuration file must be used that transmits the necessary startup information to Intel MPI. The file should contain a line with at least the following entries:

SLURM jobs:

-hosts $SLURMD_NODENAME ./h.exe  

Loadleveler jobs:

-machines $LOADL_HOSTFILE ./h.exe 

Other Intel MPI options like -genvall or -n <task count> etc. can also be added, but this is only necessary for specialized setups. The executables' name and its command line arguments are taken from this configuration file, so care must be taken to keep these consistent.

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, available from the Intel web site