marcoylyu
marcoylyu

Reputation: 31

Error when using MKL and Eigen LAPACK simultaneously

I am trying to run SVD from the Eigen library with MKL but get the following errors

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.

I have the latest version of MKL, and my cpp file is

//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;
}

and I use the following command to run the code

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

where echo ${MKLROOT} gives

/opt/intel/compilers_and_libraries_2020.2.258/mac/mkl

But the code actually works fine when I keep only #define EIGEN_USE_MKL_VML, but I get segmentation fault 11 when I keep the LAPACKE. Can someone tell me what's going on here?

Upvotes: 3

Views: 648

Answers (1)

Evg
Evg

Reputation: 26302

I see the option -DMKL_ILP64 in your command line. Under ILP64, MKL_INT and lapack_int are type aliases for long long, under LP64 they are aliases for int. Hence, the error message (though it is not clear how it is related to a segfault): you can't assign int* to long long*. But the Eigen documentation states that only LP64 is supported (emphasis is mine):

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).

Try to remove -DMKL_ILP64 flag and link against LP64 library version.

Upvotes: 4

Related Questions