Skip to content

Intel oneAPI MKL

Intel oneAPI Math Kernel Library (oneMKL) provides highly optimized, threaded routines for linear algebra (BLAS, LAPACK, ScaLAPACK), FFT, sparse solvers, and random number generation, with interfaces for C, C++, and Fortran.

Loading the module

module load imkl/2023.1.0

To see all installed versions across clusters, check the software catalog or run module spider imkl.

Info

MKL is loaded automatically when you use Intel toolchains (intel, iimpi). Check module list before adding a separate imkl load.

Compiling against MKL

The simplest way to link MKL is the -qmkl flag with the Intel compilers:

# C++
icpx -o example example.cpp -qmkl

# Fortran
ifx -o example example.f90 -qmkl

With GCC, link explicitly:

gcc -o example example.c -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm

MKL Link Line Advisor

For complex linking scenarios (threading, ILP64, static), use the Intel MKL Link Line Advisor.

Example: DGEMM matrix multiplication
#include <iostream>
#include <mkl.h>

int main() {
    const int m = 2, n = 3, k = 2;
    double A[4] = {1.0, 2.0, 3.0, 4.0};
    double B[6] = {5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
    double C[6] = {0.0};

    cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans,
                m, n, k, 1.0, A, k, B, n, 0.0, C, n);

    std::cout << "Result matrix C:" << std::endl;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++)
            std::cout << C[i * n + j] << " ";
        std::cout << std::endl;
    }
    return 0;
}

Batch job example

mkl.slurm
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=mkl
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem=4G
#SBATCH --time=00:30:00
#SBATCH --output=%x.%j.out
#SBATCH --error=%x.%j.err

module load imkl/2023.1.0

./example

Thread control

MKL uses OpenMP threading by default. Set MKL_NUM_THREADS or OMP_NUM_THREADS to control parallelism, and match with --cpus-per-task in your SLURM request.

See also