General Information

Home pageVersionsModule dependencies

The Intel Math Kernel Library (MKL) contains highly optimised, extensively multithreaded math routines for different areas of computation. The library includes:

  • BLAS (level 1, 2, and 3) and LAPACK linear algebra routines
  • ScaLAPACK distributed processing routines and BLACS routines for communication
  • Fast Fourier transform (FFT) functions
  • Vectorized math functions
  • Random number generation functions

See the Developer Reference Manuals listed  below for a complete list of all functions included in the library.

Intel MKL is optimised for the latest Intel processors. The cluster components of the library, ScaLAPACK and Cluster FFT, are built on top of MPI.

Usage on Vilje

Load one of the intel compiler modules to use the MKL library on Vilje, e.g.:

$ module load intelcomp/14.0.1

Linking Example Program

blas_test.c Expand source

The examples below show different ways of compiling and linking the sample program with MKL using the Intel compiler.

Dynamic Linking using the -mkl Compiler Option

Specifying the following commands will at compile time build single-threaded or multi-threaded executables respectively.

$ icc -mkl=sequential blas_test.c          # single-threaded
$ icc -mkl=parallel blas_test.c            # multi-threaded

When running a multi-threaded executable specify the number of threads at run-time using the OMP_NUM_THREADS or MKL_NUM_THREADS environment variables. E.g.

$ export MKL_NUM_THREADS=8
$ ./a.out
Single Dynamic Library

Linking MKL can be done using the Single Dynamic Library (SDL), For example:

$ icc blas_test.c -lmkl_rt

SDL enables you to select the threading library for MKL at run-time using the MKL_THREADING_LAYER environment variable. By default on Vilje, specified in the Intel compiler module files, this is set to be SEQUENTIAL, i.e. running applications linked with MKL through SDL in single-threaded mode. Choosing multi-threaded mode, set the variable to INTEL and specify the number of threads using the OMP_NUM_THREADS or MKL_NUM_THREADS environment variables. E.g.

$ export MKL_NUM_THREADS=8
$ ./a.out
Static Linking

In case of static linking, enclose the libraries in grouping symbols. For single-threaded version:

$ icc blas_test.c -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a ${MKLROOT}/lib/intel64/libmkl_core.a ${MKLROOT}/lib/intel64/libmkl_sequential.a -Wl,--end-group -lpthread

For multi-threaded version:

$ icc blas_test.c -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_lp64.a ${MKLROOT}/lib/intel64/libmkl_core.a ${MKLROOT}/lib/intel64/libmkl_intel_thread.a -Wl,--end-group -openmp -lpthread

ScaLAPACK and Cluster FFTs

When linking with ScaLAPACK or the Cluster FFTs part of MKL specify at the link stage:

-Wl,--start-group \
    ${MKLPATH}/ ${MKLPATH}/libmkl_intel_lp64.a \
    ${MKLPATH}/ ${MKLPATH}/libmkl_core.a \
    ${MKLPATH}/libmkl_blacs_sgimpt_lp64.a \
-Wl,--end-group  -lpthread

where you replace above:

Sequential libraryMulti-threaded library

For example, to link a Fortran program, prog.f90, with multi-threaded ScaLAPACK specify:

$ module load mpt
$ ifort prog.f90 -Wl,--start-group ${MKLPATH}/libmkl_scalapack_lp64.a ${MKLPATH}/libmkl_intel_lp64.a ${MKLPATH}/libmkl_intel_thread.a ${MKLPATH}/libmkl_core.a ${MKLPATH}/libmkl_blacs_sgimpt_lp64.a -Wl,--end-group -openmp -lpthread -lmpi

FFTW3 Interface to MKL

Intel MKL provides FFTW3 intefaces to enable applications using FFTW to gain performance with Intel MKL without changing the program source code. The FFTW3 interface is integrated in the Intel MKL core libraries which means the only change needed to build your application with FFTW3 wrappers replacing original FFTW library is to add MKL at the link stage, see Linking Example Program above.

Further Information

Scroll to Top