Use BLAS and LAPACK from Eigen
Asked Answered
C

2

9

I've implemented a piece of code with Eigen and I would like Eigen to use BLAS and LAPACK .

I've seen here, that is possible but I don't know how or where to put those values/directives in the code.

I have to expecify somewhere the value EIGEN_USE_BLAS but I have no idea where.

I've seen that Eigen's source includes the code of BLAS and LAPACK, but I completelly ignore if it uses it by default or what. I'm using Eigen 3.3.3.

Chassepot answered 10/4, 2017 at 16:10 Comment(0)
R
5

You don't put those directives in the code, you compile your code with these macros. For example:

LAPACK_FLAGS=('-D EIGEN_USE_LAPACKE=1 -lm -lblas -llapack -llapacke')
g++ --std=c++11 eigenSVD.cpp -o eigenSVD.cpp ${LAPACK_FLAGS[@]}

Take a look at Eigen/SVD, if your code is compiled with EIGEN_USE_LAPACKE, you see Eigen-lapacke interface and lapacke header files will be included.

#if defined(EIGEN_USE_LAPACKE) && !defined(EIGEN_USE_LAPACKE_STRICT)
#ifdef EIGEN_USE_MKL
#include "mkl_lapacke.h"
#else
#include "src/misc/lapacke.h"
#endif
#include "src/SVD/JacobiSVD_LAPACKE.h"
#endif
Robers answered 20/2, 2019 at 12:14 Comment(0)
C
1

Well, I have found the solution

Include in your .h file the following:

// includes to make Eigen use BLAS+LAPACK
#include <complex>

#define EIGEN_SUPERLU_SUPPORT
#define EIGEN_USE_BLAS
#define EIGEN_USE_LAPACKE

#define LAPACK_COMPLEX_CUSTOM
#define lapack_complex_float std::complex<float>
#define lapack_complex_double std::complex<double>

// includes to call Eigen
#include <Eigen/Sparse>
#include <Eigen/StdVector>

The complex includes are necessary regardless of the use of complex matrices because LAPACK demmands you to define what you call a complex type.

Chassepot answered 11/4, 2017 at 9:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.