GNU Compiler Collection (GCC)¶
The GNU Compiler Collection (GCC) consists of the following tools to compile C, C++ and Fortran programs:
gcc | GNU C compiler |
g++ | GNU C++ compiler |
gfortran | GNU Fortran compiler |
gccgo | GNU Go Compiler |
Versions and Availability¶
We generally support the last three major versions. You can get a list of available versions using the command module avail compiler/gnu
.
Environment variables¶
To see a list of all environment variables set by the modules use the command module show compiler/gnu/version
.
Example:
setenv("CC","/opt/gcc/10/bin/gcc")
setenv("CXX","/opt/gcc/10/bin/g++")
setenv("F77","/opt/gcc/10/bin/gfortran")
setenv("FC","/opt/gcc/10/bin/gfortran")
setenv("CFLAGS","-O2 -march=native")
setenv("CXXFLAGS","-O2 -march=native")
setenv("FFLAGS","-O2 -march=native")
setenv("FCFLAGS","-O2 -march=native")
setenv("OMP_PROC_BIND","true")
setenv("OMP_PLACES","cores")
...
Documentation¶
The official documentation can be found here. For a detailed lists of the different program options you can also consult the man pages installed on HoreKa:
$ man gcc
$ man g++
$ man gfortran
Optimizations¶
You can turn on various optimization options to enhance the performance of your program. Which options are the best depends on the specific program and can be determined by benchmarking your code. A command which gives good performance and a decent file size is
$ gcc -march=native -O2 ex.c -o ex
There are more aggressive optimization flags but the compiled programs can get quite large and the compilation process will probably take much longer. Moreover it can happen that the so compiled program is even slower. Such a command would be for example
$ gcc -march=native -O3 ex.c -o ex
For a complete list of all the optimization options execute
$ gcc --help=optimizers