Skip to content

Compiling Software

If the software you need is not available as a module, cannot be installed with EasyBuild or Conda, you can compile it yourself and install it into your home or project directory.

Toolchains

Compilers and libraries are provided as modules built with EasyBuild. They are grouped into toolchains, which load a compatible set of compilers and libraries at once.

Toolchain Contents
GCC GNU C, C++ and Fortran compilers.
gompi GCC + OpenMPI.
foss gompi + OpenBLAS, FFTW and ScaLAPACK (linear algebra and FFT libraries).
module spider foss                  # List available toolchain versions
module load foss/<version>          # Load compilers and libraries
gcc --version                       # Check compiler version

Tip

Use the same toolchain version for all libraries your program depends on. Modules built with different toolchain versions usually cannot be loaded together.

Compiling On Compute Node

All compute nodes use AMD EPYC 9004 (Zen 4) processors. Compile in an Interactive Job on a compute node, so the compiler can use all features of the processor and compilation does not load the login node.

qsub -I -l select=1:ncpus=16:mem=32gb -l walltime=02:00:00
module load foss/<version>

Optimization Flags

Flag Meaning
-O2 Standard optimization, safe for almost all code.
-O3 Aggressive optimization, including vectorization.
-march=znver4 Use all instructions of AMD Zen 4 processors, including AVX-512.
-fopenmp Enable OpenMP multi-threading.

Example

gcc -O3 -march=znver4 -fopenmp my_program.c -o my_program          # C with OpenMP
gfortran -O3 -march=znver4 my_program.f90 -o my_program            # Fortran
mpicc -O3 -march=znver4 my_mpi_program.c -o my_mpi_program         # C with MPI

Warning

Programs compiled with -march=znver4 run only on processors supporting the Zen 4 instruction set. They may fail with Illegal instruction on other computers, for example your own laptop. The -march=znver4 flag requires GCC 13 or newer.

Building With CMake

Many projects use CMake. Install the software into your home directory using CMAKE_INSTALL_PREFIX.

module load foss/<version> CMake/<version>
git clone https://github.com/example/myapp.git
cd myapp
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=${HOME}/software/myapp \
      -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS="-march=znver4"
cmake --build build -j ${NCPUS}                     # Compile using all allocated CPUs
cmake --install build                               # Install into your home directory

Building With Configure And Make

Older projects use the configure script and make.

module load foss/<version>
./configure --prefix=${HOME}/software/myapp CFLAGS="-O3 -march=znver4"
make -j ${NCPUS}                                    # Compile using all allocated CPUs
make install                                        # Install into your home directory

Using Installed Software

Add the installation directory to your PATH, so the program can be started by its name. Load the same toolchain that was used for compilation, because the program needs its libraries at runtime.

module load foss/<version>
export PATH=${HOME}/software/myapp/bin:${PATH}
myapp --version

Tip

Put both lines into your job scripts. Do not add them to ~/.bashrc, because they would then apply to every shell and job and may conflict with other modules.