Intel Math Kernel Libraries
The Intel MKL libraries contain a variety of optimized and threaded numerical libraries including BLAS, LAPACK, and ScaLAPACK.
External Links:
Intel MKL documentation
Intel Math Kernel Library Link Line Advisor
A note about multithreaded MKL
By default, OMP_NUM_THREADS is set to 1. To allow for MKL multithreading, set OMP_NUM_THREADS to an appropriate number by setting the environment in a submit script, for example:export OMP_NUM_THREADS=3Note that the proper amount of cores must be requested when multithreading is enabled and care should be taken when using multithreaded MKL with an MPI or OpenMP program. Before setting OMP_NUM_THREADS, examine any existing software documentation, Hazel documentation and examples on running MPI-OpenMP hybrid code, and contact HPC staff for a consultation if further guidance is needed.
Example FORTRAN code to test LAPACK
Here is an example FORTRAN code that tests the LAPACK libraries, written by John Burkardt and originally hosted at FSU. The resulting output of the code is here. This sample code and output will be used in the following examples.
To avoid copy/paste errors when using, please copy these from the apps directory:
/usr/local/apps/examples/code/lapack
Linking MKL with Intel compiler
To put the MKL libraries in the path for Intel, use
module load PrgEnv-intelTo link to MKL when compiling for serial code, use
-mkl=sequential.
To link to MKL when compiling for multithreaded code, use
-mkl.
To test linking LAPACK via MKL with the Intel compiler, compile the example code above, run it and save the results, then diff the resulting output with the original example output. The only difference should be in the timestamps. (Note that normally code should never be run on a login node; this small test is an exception.)
[unityID@login]$ cp -r /usr/local/apps/examples/code/lapack . [unityID@login]$ cd lapack [unityID@login]$ module purge [unityID@login]$ module load PrgEnv-intel [unityID@login]$ ifort -o lapack_intel lapack_examples_test.f -mkl=sequential [unityID@login]$ ./lapack_intel > results_lapack_intel.txt 0 [unityID@login]$ diff results_lapack_intel.txt lapack_examples_test.txt 1c1 < 20190618 103806.118 --- > 20180309 134600.190 836c836 < 20190618 103806.134 --- > 20180309 134600.192
Linking MKL with GNU compiler
To put the MKL libraries in the path for GNU, use
module load mklTo link to MKL when compiling, for serial code, use the linker flags
-lmkl_gf_lp64 -lmkl_core -lmkl_sequential.
To link to MKL when compiling, for multithreaded code, use the openmp flag
-fopenmp and the linker flags -lmkl_gf_lp64 -lmkl_core -lmkl_gnu_thread.
To test linking LAPACK via MKL with the GNU compiler, compile the example code above, run it and save the results, then diff the resulting output with the original example output. The only difference should be in the timestamps. (Note that normally code should never be run on a login node; this small test is an exception.)
[unityID@login]$ cp -r /usr/local/apps/examples/code/lapack . [unityID@login]$ cd lapack [unityID@login]$ module load mkl [unityID@login]$ gfortran -o lapack_gcc lapack_examples_test.f -lmkl_gf_lp64 -lmkl_core -lmkl_sequential [unityID@login]$ ./lapack_gcc > results_lapack_gcc.txt STOP 0 [unityID@login]$ diff results_lapack_gcc.txt lapack_examples_test.txt 1c1 < 20190618 104334.235 --- > 20180309 134600.190 836c836 < 20190618 104334.248 --- > 20180309 134600.192
Intel MKL link line advisor
The above examples work for basic BLAS and LAPACK libraries. To specify more detailed arguments for MPI based MKL libraries such as ScaLAPACK, see the
Intel Math Kernel Library Link Line Advisor.
Examples of other library linking flags include
-lmkl_scalapack_lp64 -lmkl_cdft_core -lmkl_blacs_intelmpi_lp64 -lmkl_blacs_openmpi_lp64
Last modified: March 20 2026 07:39:23.