Intel Math Kernel Library (MKL)¶
Intel MKL provides a collection of numerical functions covering linear algebra, statistics, nonlinear optimization, fast Fourier transform and other similar topics.
The Intel Math Kernel Library
is available on Apocrita, as part of the Intel compiler and tools suite. It
can be accessed through the module system. The library
provides routines covering a range of numerical areas, including implementations
of the BLAS and LAPACK
specifications for linear algebra. Intel MKL can be used as an alternative to
the reference LAPACK implementation provided by the
lapack
modules.
Intel MKL is directly accessible through C (header file mkl.h
) and Fortran
(mkl.fi
) interfaces.
Using Intel MKL with the Intel compilers¶
Intel MKL is most easily used with the Intel compilers installed on Apocrita.
Each version of an Intel compiler module provides the corresponding release
of the MKL package. Once an intel/
module has been loaded, the compiler
flag -mkl
can be used to make available the MKL header files, modules and
library objects. For example, to compile the Fortran source file
mkl-program.f90
using MKL:
module load intel
ifort -mkl mkl-program.f90
Similarly for the C source file mkl-program.c
:
module load intel
icc -mkl mkl-program.c
Using -mkl
to compile selects the appropriate version of the MKL package
for the size of integer variables, use of threading and whether linking is
against the dynamic or static objects. An alternative to using the -mkl
compiler option is to specify the corresponding flags manually. The required
flags can be found using the Intel MKL Link Line Advisor tool.
Some versions of the Intel modules also provide pkg-config
files to provide
the flags:
module load intel
# Get flags for compilation
pkg-config --cflags mkl-dynamic-lp64-iomp
# Get flags for linking
pkg-config --libs mkl-dynamic-lp64-iomp
We can also pkg-config
in simple compilation command lines:
module load intel
icc $(pkg-config --cflags mkl-dynamic-lp64-iomp) mkl-program.c \
$(pkg-config --libs mkl-dynamic-lp64-iomp)
Using MKL Fortran modules¶
The MKL package provides Fortran module files in addition to the Fortran
include file mkl.fi
for some components of the library, such as the
LAPACK95 module lapack95
. The compiler flag -mkl
allows these modules
to be found.
Using Intel MKL with GCC compilers¶
Intel MKL may be used with the GCC compilers installed on Apocrita. The
Intel MKL Link Line Advisor tool can be used to determine the
required compiler and link flags to access the package. The variable
MKLROOT
, referred to in the advisor output, should be set to the directory
where the version of MKL is installed. The correct value can be found by
querying the intel/
module corresponding to the installation. For example,
in Bash:
export MKLROOT=$(module load intel; echo $MKLROOT)
module load gcc
gcc mkl-program.c ...
where ...
represents the required compiler flags given by the advisor.
Building and using MKL Fortran modules¶
The MKL package provides Fortran module files in addition to the Fortran
include file mkl.fi
for some components of the library, such as the
LAPACK95 module lapack95
. However, the .mod
files in the MKL installation
are not compatible with the GNU Fortran compiler: before the Fortran modules
can be used with other compilers, compatible module files must first be built
from the available source files. For example, to build the modules for LAPACK95
in Bash we may use:
# Move to a temporary location for building
cd /data/scratch/$USER
# Find the root of the MKL installation
export MKLROOT=$(module load intel; echo $MKLROOT)
# Load a module to set up our GCC environment
module load gcc
# Set the location of where to install the interfaces
export F95ROOT=$HOME/mkl-lapack95
# Copy the modue source files from the MKL installation
cp -r $MKLROOT/interfaces/lapack95 .
# Build (this also installs) the interfaces
make -C lapack95 libintel64 INSTALL_DIR=$F95ROOT
The variable F95ROOT
is then used in the command line provided by the Link
Advisor tool.