NERSCPowering Scientific Discovery Since 1974

Cray Compilers (Fortran, C, C++)


The Cray Fortran, C, and C++ compilers are available on Cray systems, Cori and Edison.  To make this compiler the one used by the ftn, cc, and CC compiler wrappers, type in the following:

module swap PrgEnv-intel PrgEnv-cray

Cray compiler bugs affecting NERSC systems are listed at Cray compiler bugs.

Source Files and Language Dialects

The Cray Fortran compiler supports the following file extensions

.f, .F, .f90, .F90, .f95, .F95, .f03, .F03, .f08, .F08, .ftn., and .FTN

The default is source form is fixed for source files that have a .f or .F suffix.  The default is free for source files that have a .f90, .F90, .f95, .F95, .f03, .F03, .f08, .F08, .ftn, or .FTN suffix.

 To change the default source form, use the following flag:

-f source_form - Specifies whether the Fortran source file is written in fixed source form or free source form. For source_form, enter free or fixed.


-O n

(Default -O 2).  Specifies optimization features.  The opt values 0, 1, 2, and 3 enable you to specify increasing general levels of optimization.  The -O 1, -O 2, and -O 3 specifications do not directly correspond to the numeric optimization levels for scalar optimization and vectorization.  For example, specifying -O 3 does not necessarily enable scalar3 and vector3.  Cray reserves the right to alter the specific optimizations performed at these levels from release to release.  You can use the -e o option or the ftnlx commnad to display the optimization options used during compilation.

-O aggress

(Fortran only).   Causes the compiler to treat a program unit (for example, a subroutine or function) as a single optimization region.  Doing so can improve the optimization of large program units but also increases compile time and size.

-h aggress

(C/C++ only).   Internal compiler tables are expanded to accommodate larger loop bodies. This option can increase the compilation's time and memory size.

Debugging Options.

  • -g - Generates symbol table for debugging purposes.
  • -Gfast - Compile code for use with Cray fast-track debugging.  This option is useful only if used in conjunction with a debugger that supports fast-track debugging.  For more information, see the lgdb(1) man page.
  • -R runchk - Specifies any of a group of runtime checks for your program.  To specify more than one type of checking, specify consecutive runchk arguments, as follows: -R bs.  By default, no runtime checks are performed.   runchk can be one or more of the following suboptions:
    • b - Enables checking of array bounds.  Bounds checking is not performed on arrays dimensioned as (1).  Enables -Ooverindex.
    • c - Enables conformance checking of array operands in array expressions.
    • d - Enables a run time check for the !dir$ collapse directive and checks the validity of the loop_info, shortloop, and shortloop128 count information.
    • p - Generates run time code to check the association or allocation status of referenced POINTER variables, ALLOCATABLE arrays, or assumed-shape arrays.
    • s - Enables checking of character substring bounds.

Large Static Arrays

Errors of the form: 

//usr/lib64/libhugetlbfs.a(elflink.o): In function `adjust_overlap':
/usr/src/packages/BUILD/cray-libhugetlbfs-2.13/elflink.c:1163: relocation truncated to fit: R_X86_64_PC32 against `.bss'

can be fixed using the following compiler options 

-hpic -hdynamic

the latter of which directs the compiler driver to link dynamic libraries at runtime.


Cray documentation.