Intel Math Kernel Library (MKL) consists of high-performance, multithreaded mathematics libraries for linear algebra, fast Fourier transforms, vector math, and more.
Availability and Restrictions
Versions
OSC supports single-process use of MKL for LAPACK and BLAS levels one through three. For multi-process applications, we also support the ScaLAPACK, FFTW2, and FFTW3 MKL wrappers. MKL modules are available for the Intel, GNU, and PGI compilers. MKL is available on Oakley, Ruby, and Owens Clusters. The versions currently available at OSC are:
Version | Oakley | Ruby | owens | notes |
---|---|---|---|---|
10.3.0 | X | Default version on Oakley prior to 09/15/2015 | ||
11.1.0 | X | |||
11.2.0 | X | Default version on Ruby prior to 09/15/2015 | ||
11.2.1 | X | |||
11.2.3 | X | X | ||
11.3.2 | X | |||
11.3.3 | X* | X* | X* | |
2017.0.2 | X |
You can use module spider mkl
to view available modules for a given machine. Feel free to contact OSC Help if you need other versions for your work.
Access
MKL is available to all OSC users.
Usage
Usage on Oakley
Set-up
To load the default MKL, run the following command: module load mkl
. To load a particular version, use module load mkl/version
. For example, use module load mkl/11.2.3
to load MKL version 11.2.3. You can use module spider mkl
to view available modules.
This step is required for both building and running MKL applications.
Building With MKL
The MKL module will automatically configure your environment to locate the appropriate include files. When linking, however, you have a variety of options to choose from depending on your needs. These options come in the form of environment variables defined by the module. Which variable you include when linking will determine what particular configuration of MKL you get.
Environment Variable | Function |
---|---|
$MKL_CFLAGS |
Include flags for C |
$MKL_FFLAGS |
Include flags for Fortran |
$MKL_LIBS |
Use multithreaded MKL with 32-bit integers. This is the standard configuration. |
$MKL_LIBS_INT64 |
Use multithreaded MKL with 64-bit (“ILP64”) integers. |
$MKL_LIBS_SEQ |
Use single-threaded (“ SEQ uential”) MKL with with 32-bit integers. |
$MKL_LIBS_SEQ_INT64 |
Use single-threaded MKL with 64-bit integers. |
Notes:
- 64-bit integers are not supported by the FFTW2 wrappers. (See below.)
- The Intel compilers are specially configured for Intel MKL. If you are using this toolchain, you can use the "
-mkl
” option when linking in place of$MKL_LIBS
. - The default, multithreaded MKL libraries will automatically run in a single thread if they are called from an OpenMP parallel region. If you want to force single-threaded behavior throughout your program, choose one of the “
_SEQ
” variables from the list above.
Fortran 95 BLAS/LAPACK Wrappers
To compile Fortran 95 programs with modules, add the $MKL_F95FLAGS
variable to your compilation step. If you need 64-bit integers, use the $MKL_F95_FLAGS_INT64
instead. When linking, you will also need to use $MKL_F95LIBS
(or $MKL_F95LIBS_INT64
if using 64-bit integers). These variables will allow your programs to use the BLAS and LAPACK wrappers for MKL.
FFTW Wrappers
A number of “wrappers” are provided in the form of environment variables that allow you to use FFTW APIs with MKL. Variables ending in FLAGS
should be included with your compilation step, while variables ending in LIBS
should be included in your linking step.
Environment Variable | Function |
---|---|
$MKL_FFTW_CFLAGS |
Compile variable for C programs. |
$MKL_FFTW_FFLAGS |
Compile variable for Fortran programs. |
$MKL_FFTW2_D_CLIBS |
Linking variable for double-precision FFTW2 C programs. |
$MKL_FFTW2_D_FLIBS |
Linking variable for double-precision FFTW2 Fortran programs. |
$MKL_FFTW2_S_CLIBS |
Linking variable for single-precision FFTW2 C programs. |
$MKL_FFTW2_S_FLIBS |
Linking variable for single-precision FFTW2 Fortran programs. |
$MKL_FFTW3_CLIBS |
Linking variable for FFTW3 C programs. |
$MKL_FFTW3_FLIBS |
Linking variable for FFTW3 Fortran programs. |
Notes:
- FFTW3 is the default wrapper and should be picked up by your linker automatically. If you would prefer to use FFTW2, use the appropriate linking variable.
- The FFTW2 wrappers do not support 64-bit (“ILP64”) integers.
Examples
The following examples use the Intel compilers, though they should work using the GNU and Portland Group compilers as well.
Compiling a Fortran77 program with MKL:
ifort -c my_prog.f ifort -o my_prog my_prog.o $MKL_LIBS
Compiling a C program with MKL:
icc -c my_prog.c icc -o my_prog my_prog.o $MKL_LIBS
Compiling a module-based Fortran90/95 program with MKL:
ifort -c my_prog.f95 $MKL_F95FLAGS ifort -o my_prog my_prog.o $MKL_F95LIBS $MKL_LIBS
Compiling a C program with the double-precision FFTW2 wrapper:
icc -c $MKL_FFTW_CFLAGS -DMKL_DOUBLE my_prog.c icc -o my_prog my_prog.o $MKL_FFTW2_D_CLIBS $MKL_LIBS
Compiling a Fortran77 program with the FFTW2 wrapper:
ifort -c $MKL_FFTW_FFLAGS my_prog.f ifort -o my_prog my_prog.o $MKL_FFTW2_S_FLIBS $MKL_LIBS
Compiling a C program with the FFTW3 wrapper:
icc -c $MKL_FFTW_CFLAGS my_prog.c icc -o my_prog my_prog.o $MKL_FFTW3_CLIBS $MKL_LIBS
Compiling a Fortran program with the FFTW3 wrapper:
ifort -c $MKL_FFTW_FFLAGS my_prog.f ifort -o my_prog my_prog.o $MKL_FFTW3_CLIBS $MKL_LIBS
Advanced Usage
If you are already familiar with building MKL applications with your chosen build tool (GCC, Intel, or PGI) and you do not wish to use the convenience variables discussed above, you may wish to use the $MKLROOT
variable instead. This variable points to the installation directory for Intel MKL. All include files can be found in $MKLROOT/include
, for example, and the libraries are in $MKLROOT/lib/intel64
.
Running MKL Programs
When running an MKL program, you need to be sure to take the following steps.
-
Load the
mkl
module:module load mkl
-
If running with parallel MKL, set
OMP_NUM_THREADS
to match the number of cores per node in your process. In the bash shell, you can accomplish this with:PPNPERNODE=$(expr $(cat $PBS_NODEFILE | wc -l) / $(uniq $PBS_NODEFILE | wc -l)) export OMP_NUM_THREADS=$PPNPERNODE
Usage on Ruby
Set-up
To load the default MKL, run the following command: module load mkl
. To load a particular version, use module load mkl/version
. For example, use module load mkl/11.2.3
to load MKL version 11.2.3. You can use module spider mkl
to view available modules.
This step is required for both building and running MKL applications.
Usage on Owens
Set-up
To load the default MKL, run the following command: module load mkl
. To load a particular version, use module load mkl/version
. For example, use module load mkl/11.3.3
to load MKL version 11.3.3. You can use module spider mkl
to view available modules.
This step is required for both building and running MKL applications.