Compiling

Software to be executed on Compute Nodes can be compiled on the Head/Storage Node. However, should you need to work directly on Compute Nodes, you may launch an interactive job within Slurm (more on this further below).

Make sure that you use the right modules before using compilers and libraries (see Software Modules section).

Available Compilers

Distribution Language MPI Command Module
GNU Fortran No gfortran GCCcore
GNU C No gcc GCCcore
GNU C++ No g++ GCCcore
GNU Fortran Yes mpifort OpenMPI
GNU C Yes mpicc OpenMPI
GNU C++ Yes mpic++ OpenMPI
Intel Fortran No ifx intel-compilers
Intel C No icx intel-compilers
Intel C++ No icpx intel-compilers
Intel Fortran Yes mpiifx impi
Intel C Yes mpiicx impi
Intel C++ Yes mpiicpx impi

GNU Compilers

Command line options for the GNU compilers can be found on the GCC online documentation web site. The recommended command-line optimization options are:

  • -O2, Considers nearly all supported optimizations that do not involve a space-speed tradeoff.
  • -ftree-vectorize, Perform vectorization on trees.
  • -march=znver4, Choose the target-specific optimizations for AMD EPYC Genoa CPUs.
  • -fno-math-errno, Do not set errno after calling math functions that are executed with a single instruction

Examples

Compile serial binary on a Compute Node:

[user@hsn]$ module load GCC
[user@hsn]$ FFLAGS="-O2 -ftree-vectorize -march=znver4 -fno-math-errno"
[user@hsn]$ gfortran $FFLAGS sample.f

Compile a parallel binary on a Compute Node:

[user@hsn]$ module load OpenMPI
[user@hsn]$ FFLAGS="-O2 -ftree-vectorize -march=znver4 -fno-math-errno"
[user@hsn]$ mpifort $FFLAGS sample.f

Intel Compilers

Command line options can be found here on the OneAPI Documentation web site. The recommended command-line optimization options are:

  • -O2, Enables optimizations for speed. Vectorization is enabled.
  • -march=x86-64-v4, Tells the compiler to generate code with Advanced Vector Extensions 512-bit (IntelĀ® AVX-512).
  • -ftz, Flush denormal results to zero.
  • -fp-speculation=safe, Tells the compiler to disable speculation on floating-point operations if there is a possibility that the speculation may cause a floating-point exception.
  • -fp-model precise, Disables optimizations that are not value-safe on floating-point data.

Examples

Compile serial binary on a Compute Node:

[user@hsn]$ module load intel-compilers
[user@hsn]$ FFLAGS="-O2 -march=x86-64-v4 -ftz -fp-speculation=safe -fp-model precise"
[user@hsn]$ ifx $FFLAGS sample.f

Compile a parallel binary on a Compute Node:

[user@hsn]$ module load impi
[user@hsn]$ FFLAGS="-O2 -march=x86-64-v4 -ftz -fp-speculation=safe -fp-model precise"
[user@hsn]$ mpiifx $FFLAGS sample.f

Compiling code on Compute Nodes

Instant user access to compute nodes (for instance via ssh) is not allowed unless you have a job running on that node. It is however possible to launch an interactive shell (ex. bash) on a Compute Node using Slurm. In the example below we are requesting one core to launch bash, and once the shell is running, we may load the necessary software modules and run the compiler interactively:

[user@hsn]$ srun --ntasks=1 --pty bash -i
[user@cn1]$ module load GCC
[user@cn1]$ FFLAGS="-O2 -ftree-vectorize -march=znver4 -fno-math-errno"
[user@cn1]$ gfortran $FFLAGS sample.f