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:
- MKL version: Intel(R) oneAPI Math Kernel Library Version 2022.1-Product Build 20220311 for Intel(R) 64 architecture applications
- Eigen3 version: 3.4.0
- icpc (ICC) version: 2021.6.0 20220226