GCC is the standard compiler for Linux (and many Unix systems) and it is likely that any open-source, third-party, program you encounter is either developed with, or have been tested, with GCC. That makes it a safe choice for producing binaries on our systems.
In general, GCC, will not produce as fast code as Intel's compiler, which can typically be 20-30% faster (see e.g. the Polyhedron benchmarks), but it varies a lot depending on the program, and the optimization capabilities of GCC have improved a lot recently.
There are two kinds of GCC compilers that you can use at NSC:
/usr/bin/gccand come with the CentOS operating system. We do not recommend using them to compile your own codes, as they are not integrated into our HPC environment. Instead, the system compiler is mainly intended for building Linux system software and RPMs.
module avail. These are the HPC compilers that we recommend using for your own software.
So, to use GCC, just load a gcc module:
module load gcc/4.8.2
And you will find the
gfortran commands in your PATH. Generally, we don't have other languages than C/C++ and Fortran activated in gcc. If you need other GCC languages activated, such as Ada or Obj-C, please contact .
Suppose you have a file
myprogram.f90 that you want to compile. Do like this:
gfortran -o myprogram.exe -O3 myprogram.f90
That will produce the executable
myprogram.exe with optimization level
-O3 (see more below). If your program uses BLAS, LAPACK, or FFTW, we recommend using the subroutines included in Intel's Math Kernel Library. To do that, you need to first load an MKL module. E.g.
module load mkl/18.104.22.168
This command will enable the
-Nmkl flag, which you can use to simplify linking MKL with gfortran:
gfortran -o myprogram.exe -O3 -Nmkl -lmkl_gf_lp64 -lmkl_core -lmkl_sequential -lpthread -lm myprogram.f90
-Nmkl flag is specific to NSC and links your program permanently against the currently loaded Intel MKL module, but please note that you still have supply the correct libraries. We refer to the math libraries page for more information about using MKL and the other math libraries at NSC.
We have generally found gcc to be less prone to breaking code, so you can try
-O3 optimization level from the start:
|Triolith/Krypton||-O3 -mavx -march=native|
|Kappa/Matter||-O3 -msse4.2 -march=native|
It is crucial that you supply optimization flags, because otherwise gcc will compile your program with
-O0, which is very slow and not suitable for production calculations. For the most aggressive set of optimizations, you could try:
gcc -Ofast -march=native -flto -funroll-loops
This activates "unsafe" mathematics, link-time optimization, and extensive loop unrolling. It may not necessary be faster than straight
-O3, and could introduce numerical imprecision in the evaluation of floating-point expressions.