This is the guidance for compiling a code in Linux. We use VASP as an example. For full compile guidance of VASP, you can check compile_vasp.

Code Location (Fornax)

  • Base directory:
    /home/app/source
    
  • Example (VASP 6.6.0):
    /home/app/source/vasp.6.6.0
    

What “Compiling” Actually Means

Convert human-readable source code into machine-executable binaries.

  • source code (.f90, .c) → compiler → executable (vasp_std, etc.)

Compilers (Critical for DFT Codes)

GNU (GCC)

  • Free, open-source
  • Common but usually not optimal for VASP performance
  • Tools: gcc, gfortran

Intel OneAPI (Default for CPU VASP)

  • Not open-source but free for academia
  • Best performance with MKL

Compilers

  • Modern: ifx, mpiifx
  • Deprecated: ifort, mpiifort Some people say classical compiler (ifort) is faster

MPI Wrappers

These wrap compilers and handle MPI linking.

  • Intel MPI: mpiifx
  • OpenMPI: mpif90

Other Compilers

  • NVIDIA: nvfortran (in NVHPC)
  • AMD: aocc (not sure whether this is faster)

Makefile Basics

Compilation is controlled by Makefile:

make -jN
  • -jN = parallel compilation
  • Not all steps parallelize efficiently Example:
all:
	cc a.c -o a
	cc b.c -o b
 
clean:
	rm -f a b

Linking

Dynamic Linking

  • Smaller binaries
  • Depends on runtime libraries (modules must match)
  • Default on clusters

Static Linking

  • Larger binaries
  • More portable
  • Often problematic with MPI

Parallelization Model

MethodMemory Model
MPIDistributed memory
OpenMPShared memory
  • MPI: scalable but memory-heavy, use MPI as possible
  • OpenMP: easier but limited scaling. GPU version should use this as possible.
  • VASP uses hybrid MPI + OpenMP

Compiling VASP

Choose Makefile Template

From:

arch/

Example (Fornax CPU build):

makefile.include.intel_ompi_mkl_omp

Meaning:

  • intel → compiler

  • ompi → OpenMPI

  • mkl → Intel MKL

  • omp → OpenMP

  • We use openmpi version but we use intelmpi instead, i.e. Intel Compiler + Intel MPI + Intel MKL + OpenMP Reference: https://www.vasp.at/wiki/Makefile.include

Compiler Flags

Optimization:

OFLAG  = -O3   -xCORE-AVX512 -qopt-zmm-usage=high
  • If unstable → use -O2 CPU-specific:
  • AMD Genoa: -march=znver4
  • AVX512 (highly recommended): -axCORE-AVX512 -qopt-zmm-usage=high

MKL Linking

Use Intel MKL Link Advisor. https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html

Here I choose OneMKL2023, Linux, Fortran, Intel Fortran Compiler, Intel 64, Dynamic, Fortran API with 32-bit integer, OopenMP threading, libiomp5, ScaLAPACK, BLACS, Intel MPI.

FCL        += -qmkl=parallel
INCS        = -I$(MKLROOT)/include/fftw 
LLIBS      +=  -qmkl=parallel  -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64

Build Commands

make veryclean
make all -j32 DEPS=1

For VASP you should put DEPS=1 otherwise compilation will crash.

VTST (NEB Extension)

For NEB / transition states: