This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Using Eigen with BLAS/LAPACK, but not with Intel MKL

Tags: None
(comma "," separated)
allanmulin
Registered Member
Posts
14
Karma
0
I am trying to use Eigen 3.2.2 with OpenBLAS as a backend, but I get a fatal error during compilation when I define EIGEN_USE_BLAS before the Eigen headers are included:
Code: Select all
#define EIGEN_USE_BLAS
#include <Eigen/Dense>

This happens because the header file mkl.h cannot be found. It seems that Eigen still only provide support for Intel MKL's library, but in this thread https://forum.kde.org/viewtopic.php?f=74&t=110509, it is said that linking with OpenBLAS is possible.

Can Eigen really link to OpenBLAS (or any other BLAS library)? What about LAPACKE?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, after some checks this would require some minor and quite straightforward adjustments in Eigen's MKL wrapper to remove the strict dependence to MKL. Any volunteer?
allanmulin
Registered Member
Posts
14
Karma
0
Where are these minor changes necessary?
Iriasthor
Registered Member
Posts
2
Karma
0
I am interested in this topic too, and I would like to use OpenBlas with Eigen, if possible.

I am not an expert on programming. However, I have been digging the Eigen files a bit and I have noticed some references to MKL and EIGEN_USE_BLAS. As default, the EIGEN_USE_BLAS define points to MKL functionalities. The file Core at Eigen's files shows the following:

Code: Select all
#ifdef EIGEN_USE_BLAS
#include "src/Core/products/GeneralMatrixMatrix_MKL.h"
#include "src/Core/products/GeneralMatrixVector_MKL.h"
#include "src/Core/products/GeneralMatrixMatrixTriangular_MKL.h"
#include "src/Core/products/SelfadjointMatrixMatrix_MKL.h"
#include "src/Core/products/SelfadjointMatrixVector_MKL.h"
#include "src/Core/products/TriangularMatrixMatrix_MKL.h"
#include "src/Core/products/TriangularMatrixVector_MKL.h"
#include "src/Core/products/TriangularSolverMatrix_MKL.h"
#endif // EIGEN_USE_BLAS


So, if I am not wrong, I guess these are the lines that need to be changed.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Basically, in src/util/Core/MklSupport.h we should not include mkl.h by default, then defines the MKL_* types, include misc/blas.h, add the "_" prefix to BLAS calls in Core/products/*MKL.h, and update the blas.h file wrt constness.
zhanxw
Registered Member
Posts
17
Karma
0
The coming version 3.3-beta2 seems to solve this problem:

ChangeLog:

"Relax dependency on MKL for EIGEN_USE_BLAS: any BLAS library can now be used as backend."
http://eigen.tuxfamily.org/index.php?ti ... _3.3-beta2


Right now I cannot find the download link for 3.3-beta2, but will try it whenever it's available.
Royi
Registered Member
Posts
34
Karma
0
Anyone compared different libraries which is faster on Eigen's benchmark?

Does MKL / OpenBLAS give any improvement over Eigen?

Thank You.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
with multithreading MKL and OpenBLAS should be faster, for sequential use they all are close to the hardware maximal speed.
Royi
Registered Member
Posts
34
Karma
0
What about small to medium matrices (Dynamic and Static Wise)?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
please, be more specific, "medium" size does tell much. Eventually, the best way to get your answer is to bench the two options for your own problem, it is just a matter of compiling with -DEIGEN_USE_BLAS -lopenblas
Royi
Registered Member
Posts
34
Karma
0
I'd say medium is matrices with up to 2500 Elements.

Small I'd say matrices with up to 250 Elements.


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]