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

Is Eigen matrix inverse multi-threads?

Tags: None
(comma "," separated)
chunkaowang
Registered Member
Posts
5
Karma
0
I tested Eigen matrix inverse with 2, 4 or 8 threads but the wall time is almost same for the three situations.
So I want to ask if Eigen matrix inverse use multi-threads in calculation? Thank you.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Only if you compile with openmp enabled ( -fopenmp with gcc).
chunkaowang
Registered Member
Posts
5
Karma
0
I tried to compile Eigen with -fopenmp -march=native -O2.
But the running time for matrix inverse is till similar, e.g. 31-36 seconds with matrix of size 5000, whatever I used 1, 2 or 4 threads.
When the matrix inverse program run, I found at first Eigen use multi-threads, but late just one thread.
Is there any special setting for Eigen to run multi-threads?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, currently only matrix-matrix products is multi-threaded. To compute the inverse, we first start by computing a LU factorization that is dominated by matrix-matrix products. Then the U^1 * L^1 * I is performed, but since this step do rely on matrix-matrix products it does not exploit multithreading.

btw, in general nobody explicitly compute the inverse of a matrix A but rather compute its factorization (e.g. LU) and them perform calls to the solve method to efficiently apply A^1.
chunkaowang
Registered Member
Posts
5
Karma
0
My question is how i can do LU factorization first and then do solve using LU? Thank you!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
x = A.lu().solve(b);

or if you want to apply A^-1 multiple times:

PartialPivLU<MatrixXd> lu(A);
x = lu.solve(b);
y = lu.solve(c);


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]