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 HPC2021 system, users should use the environment module command:

System Compiler version Module command
HPC2021 8.5.0 Default System Compiler (need to do nothing)
9.2 module load gcc/9.2
10.2 module load gcc/10.2
12.3 (default with loaded without specifying a version) module load gcc/12.3

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 Cascade Lake 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.
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: https://gcc.gnu.org/
GCC Online documentation: https://gcc.gnu.org/onlinedocs/