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|
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.
|-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.
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.
|-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|