我尝试使用 MKL 从 Eigen 库运行 SVD,但出现以下错误
In file included from blas_mkl.cpp:6:
In file included from /usr/local/include/eigen3/Eigen/SVD:11:
In file included from /usr/local/include/eigen3/Eigen/QR:45:
/usr/local/include/eigen3/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h:85:1: error: cannot initialize a variable of type 'long long *' with an rvalue of type
'Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >::Scalar *' (aka 'int *')
EIGEN_LAPACKE_QR_COLPIV(double, double, d, ColMajor, LAPACK_COL_MAJOR)
...
/usr/local/include/eigen3/Eigen/src/QR/ColPivHouseholderQR_LAPACKE.h:74:15: note: expanded from macro 'EIGEN_LAPACKE_QR_COLPIV'
lapack_int *perm = m_colsPermutation.indices().data(); \
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 errors generated.
我有最新版本的MKL
,我的cpp文件是
//blas_mkl.cpp
#define EIGEN_USE_MKL_VML
#define EIGEN_USE_LAPACKE
#include <iostream>
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/SVD>
using namespace Eigen;
using namespace std;
int main() {
MatrixXf data(4, 2);
data << 76, 8,
0, 0,
82, 3,
80, 0;
JacobiSVD<MatrixXf> svd(data, ComputeThinU | ComputeThinV);
cout << svd.matrixU() * svd.singularValues().asDiagonal() * svd.matrixV().transpose() << endl;
cout << data << endl;
return 0;
}
我使用以下命令来运行代码
g++ -DMKL_ILP64 -m64 -I${MKLROOT}/include ${MKLROOT}/lib/libmkl_intel_ilp64.a ${MKLROOT}/lib/libmkl_intel_thread.a ${MKLROOT}/lib/libmkl_core.a -liomp5 -lpthread -lm -ldl -o blas_mkl blas_mkl.cpp
其中 echo ${MKLROOT}
给出
/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl
但是当我只保留#define EIGEN_USE_MKL_VML
时,代码实际上工作得很好,但是当我保留LAPACKE时,我得到了段错误11。有人能告诉我这是怎么回事吗?
最佳答案
我在命令行中看到选项-DMKL_ILP64
。在 ILP64 下,MKL_INT
和 lapack_int
是 long long
的类型别名,在 LP64 下它们是 int
的别名。因此,错误消息(尽管尚不清楚它与段错误有何关系):您无法将 int*
分配给 long long*
。但 Eigen documentation声明仅支持 LP64(重点是我的):
Using Intel MKL through Eigen is easy:
define the
EIGEN_USE_MKL_ALL
macro before including any Eigen's header, link your program to MKL libraries (see the MKL linking advisor), on a 64bits system, you must use the LP64 interface (not the ILP64 one).
尝试删除 -DMKL_ILP64
标志并链接到 LP64 库版本。
关于c++ - 同时使用 MKL 和 Eigen LAPACK 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63421537/