It is relatively simple to compile and link a C, C++ or Fortran program that makes use of the Intel MKL (Math Kernel Library), especially when using the Intel compilers.
- Begin by determining the correct link parameters for your situtation at the Intel MKL Link Line Advisor page. Select the options as follows:
- Intel product:
- Intel MKL 2019.0 (if using Intel Compiler 19.x)
- Intel MKL 10.2 (if using Intel Compiler 11.x)
- Intel MKL 10.3 (if using Intel Compiler 12.x)
- Intel Composer XE 2013 (if using Intel Compiler 13.x)
- Intel OS: Linux
- Intel Fortran
- Intel C/C++
- Processor architecture: Intel 64
- Dynamic or static linking: Dynamic (recommended)
- Interface layer: 32-bit integer (_lp64) or 64-bit integer (_ilp64)
- Sequential or multi-threaded layer:
- Sequential (standard option)
- Multi-threaded (only if doing multi-threading within each process using OpenMP or TBB)
- The other options usually do not need to be specified.
- Intel product:
- Execute: module load intel/<version>
Type 'module list' to see which version's environment was set up. If you wish to use a different Intel compiler version, then type 'module avail' to see your choices, and then 'module purge' followed by a 'module load' command specifying the desired version.
- Since your selected Intel compiler and MKL environments have now been set up, there is no need to specify the -I (compilation) and -L (link) options as specified by the Link Line Advisor page. Instead, just append the other recommended link line options to your icc or ifort command invocation: e.g.,
icc -o prog prog.c -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread -lm
- Runtime threading configuration:
- If you selected the sequential layer option above, Intel MKL does not use the OpenMP threading library, and therefore there is no need to set the OMP_NUM_THREADS environment variable.
- If you specifed the multi-threaded layer, Intel MKL does use OpenMP under the hood, and you must specify in your Slurm script (to be submitted with sbatch) the number of threads to be created for each process. Please follow the relevant instructions by clicking here.
Run 'module show intel-mkl' to see the MKLROOT path. This path is often needed when building software and it fails to find MKL. For instance, when building PETSc one needs '--with-blaslapack-dir=$MKLROOT'.