0

I have the following simple code:

#include <Eigen/Dense>
int main()
{
    Eigen::MatrixXd M = Eigen::MatrixXd::Random(1000,1000);
    M = M.transpose()*M;
}

This code works great. To speed it up, I tried to use the Intel compiler and define EIGEN_USE_MKL_ALL:

#include <Eigen/Dense>
#define EIGEN_USE_MKL_ALL
int main()
{
    Eigen::MatrixXd M = Eigen::MatrixXd::Random(1000,1000);
    M = M.transpose()*M;
}

This results in a "Segmentation fault (core dumped)" error due to M.transpose() * M.

I also tried to use EIGEN_USE_BLAS and got another error: "Intel MKL ERROR: Parameter 13 was incorrect on entry to DGEMM."

Finally, if I rewrite the code using dgemm, I don't encounter any errors:

Eigen::MatrixXd M_transpose = M.transpose();
Eigen::MatrixXd M_result(size, size);
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans,
            size, size, size,
            1.0, M.data(), size,
            M_transpose.data(), size,
            0.0, M_result.data(), size);
M = std::move(M_result);

What's going on? I expected that adding definitions without modifying the code would result in a significant speedup, but even a simple matrix multiplication is causing problems.

Versions of using packages and compiler:

  1. MKL version: Intel(R) oneAPI Math Kernel Library Version 2022.1-Product Build 20220311 for Intel(R) 64 architecture applications
  2. Eigen3 version: 3.4.0
  3. icpc (ICC) version: 2021.6.0 20220226
1 1
  • 47
  • 4
  • You need to provide at least what your MKL and Eigen versions are. – Jodocus Apr 10 '23 at 12:49
  • @Jodocus, versions of using packages and compiler: 1. MKL version: Intel(R) oneAPI Math Kernel Library Version 2022.1-Product Build 20220311 for Intel(R) 64 architecture applications 2. Eigen3 version: 3.4.0 3. icpc (ICC) version: 2021.6.0 20220226 – 1 1 Apr 10 '23 at 13:27
  • The "parameter X incorrect" errors typically happen when you link incorrectly. See here https://stackoverflow.com/questions/75424748/eigen-methods-in-c-library-opencv-eigen-armadillo-considerably-slower-than/75434156#75434156 – Homer512 Apr 10 '23 at 19:04

0 Answers0