【问题标题】:Error when using MKL and Eigen LAPACK simultaneously同时使用 MKL 和 Eigen LAPACK 时出错
【发布时间】:2020-08-15 00:35:14
【问题描述】:

我正在尝试使用 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。谁能告诉我这里发生了什么?

【问题讨论】:

  • 它工作正常,你得到一个段错误或你得到一个编译错误?
  • 我在使用 LAPACKE 时遇到了段错误。

标签: c++ eigen intel-mkl


【解决方案1】:

我在您的命令行中看到了选项-DMKL_ILP64。在 ILP64 下,MKL_INTlapack_intlong long 的类型别名,在 LP64 下它们是 int 的别名。因此,错误消息(虽然不清楚它与段错误的关系):您不能将int* 分配给long long*。但是 Eigen documentation 声明只支持 LP64(重点是我的):

通过 Eigen 使用英特尔 MKL 很简单:

在包含任何 Eigen 标头之前定义 EIGEN_USE_MKL_ALL 宏,将您的程序链接到 MKL 库(请参阅 MKL 链接顾问),在 64 位系统上,您必须使用 LP64 接口(不是 ILP64 接口)。

尝试删除 -DMKL_ILP64 标志并链接到 LP64 库版本。

【讨论】:

  • 总结一下,用-DMKL_LP64代替-DMKL_ILP64。英特尔 MKL 链接线路顾问出于未知原因建议使用 ILP64。
  • @marcoylyu,你不需要MKL_LP64 符号。逻辑是#ifdef MKL_ILP64,使用ILP64,#else,使用LP64,#endif
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多