All requests for technical support from the VASP group must be addressed to: vasp.materialphysik@univie.ac.at

Linking gfortran with Intel MKL

From Vaspwiki
Jump to: navigation, search

To improve on the execution time VASP can be build with the GNU compiler suite in combination with Intel's Math Kernel Library [1]. This can reduce the execution time on Intel machines by a factor of 2 to 3 for typical DFT calculations.

This guide assumes that MKL is installed and the proper environment variables are set [2].

Note that following steps will yield a version of VASP without OpenMP support.

  • Extract the VASP tar ball
tar -xzvf vasp.VERSION.tar.gz 
cd vasp.VERSION

In the following two linking examples are provided.

  • This example uses the GNU compiler suite and an working OpenMPI and SCALAPACK install. The LAPACK and FFTW libraries are provided by MKL.
# Precompiler options
CPP_OPTIONS= -DHOST=\"LinuxGNU\" \
            -DMPI -DMPI_BLOCK=8000 -Duse_collective \
            -DscaLAPACK -DCACHE_SIZE=4000 \
            -Davoidalloc -Duse_bse_te \
            -Dtbdyn -Duse_shmem

CPP        = gcc -E -P -C -w $*$(FUFFIX) >$*$(SUFFIX) $(CPP_OPTIONS)

# make sure MKLROOT is set in your environment
FC         = mpif90 -m64 -I$(MKLROOT)/include
FCL        = mpif90 -m64 -I$(MKLROOT)/include

FREE       = -ffree-form -ffree-line-length-none 

FFLAGS     = -w
OFLAG      = -O2 -mtune=native -m64
OFLAG_IN   = $(OFLAG)
DEBUG      = -O0

# make sure SCALAPACK is installed
LIBDIR     = /path/to/scalapack-library
SCALAPACK  = -L$(LIBDIR) -lscalapack 

LLIBS      = $(SCALAPACK) 

# linking to MKL as recommended by https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/
LLIBS      += -L$(MKLROOT)/lib/intel64 -Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl

INCS       = -I$(MKLROOT)/include/fftw

OBJECTS    = fftmpiw.o fftmpi_map.o  fftw3d.o  fft3dlib.o 

OBJECTS_O1 += fftw3d.o fftmpi.o fftmpiw.o
OBJECTS_O2 += fft3dlib.o

# For what used to be vasp.5.lib
CPP_LIB    = $(CPP)
FC_LIB     = $(FC)
CC_LIB     = gcc
CFLAGS_LIB = -O
FFLAGS_LIB = -O1
FREE_LIB   = $(FREE)

OBJECTS_LIB= linpack_double.o getshmem.o 

# For the parser library
CXX_PARS   = g++  
LIBS       += parser
LLIBS      += -Lparser -lparser -lstdc++

# Normally no need to change this
SRCDIR     = ../../src
BINDIR     = ../../bin
  • This example shows linking to MKLs LAPACK, SCALAPACK and FFTW libraries and requires only a separate install of OpenMPI.
# Precompiler options
CPP_OPTIONS= -DHOST=\"LinuxGNU\" \
            -DMPI -DMPI_BLOCK=8000 -Duse_collective \
            -DscaLAPACK -DCACHE_SIZE=4000 \
            -Davoidalloc -Duse_bse_te \
            -Dtbdyn -Duse_shmem

CPP        = gcc -E -P -C -w $*$(FUFFIX) >$*$(SUFFIX) $(CPP_OPTIONS)

# make sure MKLROOT is set in your environment
FC         = mpif90 -m64 -I$(MKLROOT)/include
FCL        = mpif90 -m64 -I$(MKLROOT)/include

FREE       = -ffree-form -ffree-line-length-none 

FFLAGS     = -w
OFLAG      = -O2 -mtune=native -m64
OFLAG_IN   = $(OFLAG)
DEBUG      = -O0

# linking to MKL as recommended by https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor/
LLIBS      += -L$(MKLROOT)/lib/intel64 -Wl,--no-as-needed -lmkl_scalapack_lp64 -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lmkl_blacs_openmpi_lp64 -lgomp -lpthread -lm -ldl

INCS       = -I$(MKLROOT)/include/fftw

OBJECTS    = fftmpiw.o fftmpi_map.o  fftw3d.o  fft3dlib.o 

OBJECTS_O1 += fftw3d.o fftmpi.o fftmpiw.o
OBJECTS_O2 += fft3dlib.o

# For what used to be vasp.5.lib
CPP_LIB    = $(CPP)
FC_LIB     = $(FC)
CC_LIB     = gcc
CFLAGS_LIB = -O
FFLAGS_LIB = -O1
FREE_LIB   = $(FREE)

OBJECTS_LIB= linpack_double.o getshmem.o 

# For the parser library
CXX_PARS   = g++  
LIBS       += parser
LLIBS      += -Lparser -lparser -lstdc++

# Normally no need to change this
SRCDIR     = ../../src
BINDIR     = ../../bin
  • Build std, gam and ncl versions of VASP
make std gam ncl

After a successful build the corresponding executables are found in ./bin.