The GNU Compiler Collection (GCC) provides C/C++ and Fortran compilers.

Using GNU Compilers

The GNU compilers and debugger are available in the cluster systems. By default, user can use system provided GCC tools already. If you need some new features which is supported by different GCC version only, you can change the GCC version by:

For HPC2015 system, users should use the environment module command:

System Compiler version Module command
HPC2015 4.4.7 Default System Compiler (need to do nothing)
4.9.3 module load gcc/4.9.3
5.2.0 module load gcc/5.2.0
6.3.0 (default with loaded without specifying a version) module load gcc/6.3.0
8.2.0 module load gcc/8.2.0

Compilation Commands

C programs :
gcc [options] program.c -o program.exe
C++ programs :
g++ [options] program.cpp -o program.exe

Fortran programs :
gfortran [options] program.f -o program.exe

Using Compiler Options

Compiler option is case-sensitive. Command line expression used to change the compilers’ default operation. Compiler options are not required to compile your program, but they are useful in helping you control the code generation, optimization, linking properties, speed of executable, etc.

Option Flag Comment
-O3 Default setting is ‘-O2‘ with maximize speed. The ‘-O3‘ option enables ‘-O2‘ optimizations plus more aggressive loop and memory-access optimizations. It is particularly recommended for applications that have loops that do many floating-point calculations or process large data sets. It may result in slow down compared to ‘-O2‘ option.
-fopenmp Cause multi-threaded code to be generated when OpenMP directives are present.
march=target or -march=native Generate specialized codes that are optimized for various instruction sets(target) used in specific processors.

Processor Type System target
Intel Ivy Bridge HPC2015 (SP nodes) ivybridge
Intel Haswell HPC2015 (GP nodes) haswell
Intel Cascade Lake HPC2015 (mehpc2 nodes)
HPC2021 (frontend, GP-Intel, GPU nodes)
cascadelake (> GCC 9)
AMD Zen2/Rome HPC2021 (GP-AMD, Hugemem nodes) znver2 (>GCC 9)

The instruction set is upward compatible. Therefore, applications compiled with -march=ivybridge can run on Ivy Bridge or Haswell processors, but not on Nehalem or Westmere.
To use -march=haswell on hpc2015, you need to use a more updated GNU as than the default one. It is available by load module binutils
If you do not sure the processor type, ‘-march=native‘ will generate optimized code targeted for execution on the system you compile on.

-g Generates debug information for use with any of the common platform debuggers
-pg Generates instrumented executable which will collect data for later use with gprof

Additional Information

GNU Compiler Collection official page:
GCC Online documentation: