Registered Member
|
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? |
Moderator
|
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:
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); |
Registered Member
|
Yes. I simply need the inverse of some matrix A and for that I do
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? |
Moderator
|
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. |
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]