MKL on Lisa

Module mkl

The MKL library from Intel contains many highly-optimized math routines, most notably BLAS, LAPACK and ScaLAPACK routines. It is available via the command:

module load mkl

Choosing appropriate linking flags

Intel has a page where you can determine which link flags to use. Choose for 'version' the highest available, unless you are using a non-default mkl module. You can omit -L$MKLROOT from the flags.

Examples:

  • Intel compiler (ifort), 32 bit integers (standard):
  module load fortran mkl
  ifort prog.f -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread
# If you want the threaded version:
  ifort prog.f -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -openmp -lpthread
  • Intel compiler (ifort), 64 bit integers (for example when using the -i8 compile flag):
  module load fortran mkl
  ifort -i8 prog.f -lmkl_intel_ilp64 \
    -lmkl_sequential -lmkl_core -lpthread
# If you want the threaded version:
  ifort -i8 prog.f -lmkl_intel_ilp64 \
    -lmkl_intel_thread -lmkl_core -openmp -lpthread
  • GNU compiler (gfortran), 32 bit integers (standard):
  module load mkl
  gfortran prog.f -lmkl_gf_lp64 \
    -lmkl_sequential -lmkl_core -lpthread
# If you want the threaded version:
  gfortran prog.f -lmkl_gf_lp64 \
    -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread
  • GNU compiler (gfortran), 64 bit integers (for example when using the -fdefault-integer-8 compile flag):
  module load mkl
  gfortran prog.f -fdefault-integer-8 prog.f -lmkl_gf_ilp64 \
    -lmkl_sequential -lmkl_core -lpthread
# If you want the threaded version:
  gfortran prog.f -fdefault-integer-8 prog.f -lmkl_gf_ilp64 \
    -lmkl_gnu_thread -lmkl_core -fopenmp -lpthread

Using LAPACK routines

If you want to use the LAPACK routines from Intel, no extra flags are necessary.

Using ScaLAPACK routines

If you want to use the optimized ScaLAPACK routines available in the MKL library, use the following modules:

  module load fortran mkl openmpi

and add the following flags before the flags listed above:

# 32-bit integers:
  -lmkl_scalapack_lp64 -lmkl_blacs_openmpi_lp64
# 64-bit integers:
  -lmkl_scalapack_ilp64 -lmkl_blacs_openmpi_ilp64

Using MKL from C

We have some documentation and examples how to use MKL from a C program.

Notes

  • The threaded versions will by default use all cores available in a node.
  • Threading within the MKL library can be controlled by the environment variable OMP_NUM_THREADS and the environment variable MKL_NUM_THREADS. The latter takes precedence. For example if you are running an OPENMP program, and want that 8 threads run, but that the mkl calls in each thread do not spawn further threads, you can specify:
export OMP_NUM_THREADS=8
export MKL_NUM_THREADS=1

More about modules