问题描述
我正在尝试使用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,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,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*
。但是本征documentation指出仅支持LP64(强调是我的):
通过Eigen使用Intel MKL很容易:
定义
EIGEN_USE_MKL_ALL
宏,然后再包含任何Eigen的标头,将程序链接到MKL库(请参阅MKL链接顾问),在64位系统上,必须使用LP64接口(不是ILP64接口) )。
尝试删除-DMKL_ILP64
标志并链接到LP64库版本。