c++armadilloqt6intel-mkl

How to use intel MKL in Armadillo to invert a non-singular matrix?


Armadillo code:

    #define ARMA_DONT_USE_WRAPPER
    #define ARMA_USE_BLAS
    #define ARMA_USE_LAPACK

    arma::mat A = { { 0.0013 , 0.1741 , 0.9885 , 0.1662 , 0.8760 } ,
                   { 0.1933 , 0.7105 , 0.1191 , 0.4508 , 0.9559 } ,
                   { 0.5850 , 0.3040 , 0.0089 , 0.0571 , 0.5393 } ,
                   { 0.3503 , 0.0914 , 0.5317 , 0.7833 , 0.4621 } ,
                   { 0.8228 , 0.1473 , 0.6018 , 0.5199 , 0.8622 } };
    A.print("A: ");

    arma::mat B = arma::inv(A);
    B.print("inv(A): ");
    arma::mat I = A*B;
    I.print("I: ");

MKL targets from CMAKE:

[cmake] -- MKL_VERSION: 2024.2.0
[cmake] -- MKL_ROOT: C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2
[cmake] -- MKL_ARCH: None, set to ` intel64` by default
[cmake] -- MKL_LINK: None, set to ` dynamic` by default
[cmake] -- MKL_INTERFACE_FULL: None, set to ` intel_ilp64` by default
[cmake] -- MKL_THREADING: None, set to ` intel_thread` by default
[cmake] -- MKL_MPI: None, set to ` intelmpi` by default
[cmake] -- Found C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/lib/mkl_scalapack_ilp64_dll.lib
[cmake] -- Found DLL: C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/bin/mkl_scalapack_ilp64.2.dll
[cmake] -- Found C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/lib/mkl_cdft_core_dll.lib
[cmake] -- Found DLL: C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/bin/mkl_cdft_core.2.dll
[cmake] -- Found C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/lib/mkl_intel_ilp64_dll.lib
[cmake] -- Found C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/lib/mkl_intel_thread_dll.lib
[cmake] -- Found DLL: C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/bin/mkl_intel_thread.2.dll
[cmake] -- Found C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/lib/mkl_core_dll.lib
[cmake] -- Found DLL: C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/bin/mkl_core.2.dll
[cmake] -- Found C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/lib/mkl_blacs_ilp64_dll.lib
[cmake] -- Found DLL: C:/Program Files (x86)/Intel/oneAPI/mkl/2024.2/bin/mkl_blacs_ilp64.2.dll
[cmake] -- Found C:/Program Files (x86)/Intel/oneAPI/compiler/latest/lib/libiomp5md.lib
[cmake] -- Imported oneMKL targets: MKL::mkl_scalapack_ilp64;MKL::mkl_cdft_core;MKL::mkl_intel_ilp64;MKL::mkl_intel_thread;MKL::mkl_core;MKL::mkl_blacs_ilp64;MKL::MKL

After starting the application crashes, and the following message is shown: Intel oneMKL ERROR: Parameter 1 was incorrect on entry to DGETRF.

Armadillo can be configured via editing the file include/armadillo_bits/config.hpp:

they were defined in the code, but the error persists.

I am working in Qt Creator IDE 14, using MSVC 2022 (64bit) (Qt 6.8), Armadillo 14.0.3, and Intel OneAPI MKL 2024.2


Solution

  • OneAPI MKL may be configured to use 64 bit ints. Standard BLAS and LAPACK uses 32 bit ints.

    Enable the ARMA_BLAS_LONG_LONG option before including the Armadillo header to force the use of 64 bit ints when calling BLAS and LAPACK functions. This can be done like so:

    #define ARMA_DONT_USE_WRAPPER
    #define ARMA_BLAS_LONG_LONG
    #include <armadillo>