High-performance, multithreaded mathematics libraries for linear algebra, fast Fourier transforms, vector math, and more.
Availability & Compatibility
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.
All OSC users may use the Intel MKL for academic purposes.
To configure your environment for the Intel MKL, load the “mkl” module:
module load mkl
This step is required for both building and running MKL applications. Exception: The "mkl" module is usually not needed when using the Intel compilers; just use the "-mkl" flag on the compile and link steps.
Building With MKL (Oakley)
The Oakley 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.
||Include flags for C|
||Include flags for Fortran|
||Use multithreaded MKL with 32-bit integers. This is the standard configuration.|
||Use multithreaded MKL with 64-bit (“ILP64”) integers.|
||Use single-threaded (“
||Use single-threaded MKL with 64-bit integers.|
- 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
- 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_INT64 if using 64-bit integers). These variables will allow your programs to use the BLAS and LAPACK wrappers for MKL.
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.
||Compile variable for C programs.|
||Compile variable for Fortran programs.|
||Linking variable for double-precision FFTW2 C programs.|
||Linking variable for double-precision FFTW2 Fortran programs.|
||Linking variable for single-precision FFTW2 C programs.|
||Linking variable for single-precision FFTW2 Fortran programs.|
||Linking variable for FFTW3 C programs.|
||Linking variable for FFTW3 Fortran programs.|
- 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.
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
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
Running MKL Programs
When running an MKL program, you need to be sure to take the following steps.
module load mkl
If running with parallel MKL, set
OMP_NUM_THREADSto 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