How to build a program using Intel MKL
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 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
- Processor architecture: Intel 64
- Intel Fortran
- Intel C/C++
- Dynamic or static linking: Dynamic (recommended)
- Interface layer: LP64
- Sequential or multi-threaded layer:
- Sequential (standard option)
- Multi-threaded (only if doing multi-threading within each process using OpenMP)
- The other options usually do not need to be specified.
- Intel product:
- Execute: module load intel
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 PBS script (to be submitted with qsub) the number of threads to be created for each process. Please follow the relevant instructions by clicking here.