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

Repeated Sparse Inversion

Tags: None
(comma "," separated)
fmeirinhos
Registered Member
Posts
4
Karma
0

Repeated Sparse Inversion

Tue Jun 06, 2017 1:04 pm
In my problem I need to invert medium sized (~ 50 to 200) matrices millions of times. For this I use Eigen's Sparse LU solver.

By profiling memory allocations one sees that the number of mallocs is ever increasing (~1GB every few seconds) and this invariably makes my Linux OS to kill the program. Interestingly this does not happen on my Mac OS.

1) What exactly can I do to solve this problem?

2) Is there any way one can reduce the amount of mallocs?
2.1) For example, is there a way to use a .noalias() on Eigen::SparseLU::solve?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Repeated Sparse Inversion

Tue Jun 06, 2017 3:35 pm
Do you really need to explicitly compute the inverse? If you only want to apply it, then use the solve method. For instance if you have a complex expression like:

... (A^-1 * B) ...

with B an expression too, then do:

Code: Select all
SparseLU<SparseMatrix<double> > lu;
do {
  ...
 B = ...
  lu.compute(A);
  X = lu.solve(B);
  ...
} while(...);


finally, if the right hand side is a vector make sure to start by doing matrix-vector product/solve, for instance if f is the only vector in:

r = P * Q * A^-1 * U * V * f

then do:

b = U * (V * f);
x = lu.solve(b);
r = P * (Q * x);
fmeirinhos
Registered Member
Posts
4
Karma
0

Re: Repeated Sparse Inversion

Tue Jun 06, 2017 4:21 pm
ggael wrote:Do you really need to explicitly compute the inverse?


Yes. I simply need the inverse of some matrix A and for that I do

Code: Select all
SparseLU<SparseMatrix<double> > lu;
do {
  // ...
  lu.factorize(A);
  X = lu.solve(B);
  // ...
} while(...);


Thank you for the reply but I think the main problem was not addressed:
How can I reduce the amount of allocations on repeated LU solves? How can I prevent the OS from killing the program?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Repeated Sparse Inversion

Wed Jun 07, 2017 8:21 am
ok, so for what looks like a memory leak make sure that you are using latest Eigen release, and then check your own code for possible unallocated objects. If no luck, you can track it down using a memory debugger like valgrind. To invert such small matrices, it might be faster to use a dense solver as the result is likely to be dense anyway:

MatrixXd A;
MatrixXd invA = A.inverse();

Note that SparseLU::solve(SparseMatrix B) internally processes the sparse matrix B by converting small chunks of 1 to 4 columns as a dense matrix, so even if you stick with SparseLU it might make more sense to use a dense matrix for the inversion step.


Bookmarks



Who is online

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