Registered Member
|
Hi,
I'm trying to do sparse matrix inversion of a fairly large (but sparse) matrix and I am looking to write a code that is portable as possible and doesn't rely on my environment having certain packages installed, so Eigen seemed like a good option. Before someone makes the obligatory comment: YES! I absolutely must do an inversion, it is not the kind of problem that I can just solve a system of linear equation, I need the whole inverse. I tried inverting a simple 5000 element matrix using: (dense) PartialPiv and SparseLU (using both the compute() and analyseFunction(), factorize() methods). I then did a simple inv(matrix) command in matlab and compared the two. Matlab is roughly 10x faster. Matlab is using the 8 cores of my computer for inversion and I suppose none of the Eigen methods are doing that. I'm not sure what I can do about that without assuming my computing environment has something like SuperLU installed. I am willing to use a dense solver if it were parallel but Eigen doesn't seem to support that either (as I said I tried PartialPiv). Is there anything to be done about this? Or am I barking up the wrong tree with Eigen? I've included the bare bones code:
|
Moderator
|
PartialPivLU should be able to exploit your multiple cores. make sure you compiled with -fopenmp, and that you run your program with OMP_NUM_THREADS=8 if 8 is the number of physical cores (not the number of hyper-threads).
Could you also paste the numbers you've got to see if they are reasonable. |
Moderator
|
btw, you are using an uninitialized matrix as big_matrix is not used at all. Moreover, since the inverse is most likely to be dense, you can use a dense solving step:
takes 2.2s here without multithreading. |
Registered Member
|
Sorry, what I posted is a trimmed down version of a more complicated code where big_matrix is used and pre_final_matrix is actually the sum of a few other matrices including big_matrix. My bad. Wow, the method you suggested works WAY, WAY better. Using the first method (the dense one with PartialPivLU) I got times of approximately 87.4s Using the second method (using SparseLU and compute) I got times of approximately 78.2s Using the third method (using SparseLU and factorize) I got time of approximately 77.3s And somehow your SparseLU and solve method takes approximately 1.3s How is their such an enormous different between these methods? Thanks for the help! |
Moderator
|
PartialPivLU and SparseLU are completely different algorithms and not comparable at all. compute is just a shortcut for analyzePattern/factorize, so same speed has to be expected. SparseLU::solve(sparse), i.e., with a sparse argument, assumes that the result will be sparse and thus processes the argument per chunk of 4 columns instead of solving for all columns at once as does SparseLU::solve(dense). This hardcoded value of 4 could be adjusted to be larger for small problems as yours.
|
Moderator
|
hm, no. The reason is simply a problem of memory reallocation when filling the result matrix. The following is very good too:
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]