I am working on a project with electrical circuits, where I am trying to compute the voltages at all the nodes of an electrical circuit. I know that the electrical circuit is a perfect grid, so each node only touches at most 8 other nodes. Which means that I endup trying to solve a system:
L v = i
where L
is at least a 1000x1000 matrix where each row has only 9 non-zeros. So, it's really really sparse.
I have tried solving it using SoPlex, LaPACK and SuperLU (these last 2 through Armadillo). But all are too slow. On a 10000x10000 the best I have is 18s.
I know there is another software that does the same task as mine, written in Python that uses Scipy (scipy.sparse.linalg
to be precise) that is ridiculously fast (can solve those systems in less than one second).
Is there a library that is equivalent to Scipy or a way of porting Scipy to C++? I need to write the software in C++, for other reasons...
EDIT: My code to call SuperLU/LaPACK through Armadillo is simply:
voltages[i] = spsolve(laplacians[i],iflow[i],"lapack");
Or
voltages[i] = spsolve(laplacians[i],iflow[i],"superlu");
No options have been given before.
scipy.sparse.linalg.spsolve
is much faster? what is the storage format of your sparse matrix? do you re-order rows/columns to minimize fill-in? what's the sparsity pattern (and memory usage) of your LU factors? do you use a preconditioner? have you considered using an iterative method instead of a direct one (GMRES)? $\endgroup$spsolve
? $\endgroup$