Skip to Content

GNU Compiler

Programming Environment

To use the GNU compiler, swap in the GNU programming environment (PrgEnv-gnu) and use the wrappers for C (cc), C++ (CC), and Fortran (ftn).  To see all available compiler versions, use the command:

module avail gcc

To switch to a different version, use the command:

module swap gcc gcc/<version>

When to Use the GNU Compiler

The GNU compiler is particularly good for code that includes vectorization using inlined assembly (i.e., intrinsics).  Cray has observed outstanding performance from GNU-compiled C and C++ code (if you ignore vectorization), but only so-so performance from GNU-compiled Fortran code. 

Flags

There are numerous compile-time flags that can be used.  For complete listings, see the man pages:

man gfortran
man gcc
man g++

Cray recommends:

-O3 -ffast-math -funroll-loops

Note that using -ffast-math may change your simulation output due to rounding differences.  Be sure to check the validity of your results if you use this option.  It may not be suitable for some codes.  Also note that -funroll-loops may not make your code faster.  We recommend that you try a few short, but realistic, benchmarking runs with different combinations of these flags to see what gives you the best performance.

OpenMP

For OpenMP programs, use:

-fopenmp

For compiler feedback, use:

-ftree-vectorizer-verbose=2 -fopt-info

Fortran file naming, preprocessing

Fortran naming conventions for GNU fortran preprocessing (can override with flags)

The preprocessor is automatically invoked if the file extension is .fpp, .FPP,  .F, .FOR, .FTN, .F90, .F95, .F03 or .F08.

Underflow, Flush-to-Zero, and fast-math

When floating-point calculations result in numbers that are so small that they underflow (also called "sub-normal" numbers), GNU-compiled code normally takes a huge performance hit (which may be > 100x) while attempting to preserve the numbers.  The alternative is to flush those results to zero.  Using the -ffast-math option will do this.