chunkaowang
Registered Member

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 multithreads in calculation? Thank you. 
ggael
Moderator

Only if you compile with openmp enabled ( fopenmp with gcc).

chunkaowang
Registered Member

I tried to compile Eigen with fopenmp march=native O2.
But the running time for matrix inverse is till similar, e.g. 3136 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 multithreads, but late just one thread. Is there any special setting for Eigen to run multithreads? 
ggael
Moderator

Indeed, currently only matrixmatrix products is multithreaded. To compute the inverse, we first start by computing a LU factorization that is dominated by matrixmatrix products. Then the U^1 * L^1 * I is performed, but since this step do rely on matrixmatrix 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

My question is how i can do LU factorization first and then do solve using LU? Thank you!

ggael
Moderator

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); 
Registered users: Baidu [Spider], Bing [Bot], Exabot [Bot], Google [Bot], koriun, LukasT.dev, MichaelTiebesl, ooker, orbmiser, paulus3005, peterraven, toad, tokiedian, Yahoo [Bot]