# Use CUBLAS or CUSPARSE for matrix inversion?

I need to invert a matrix C which is calculated as C = X’ * (A)-1 * X + (B)-1, where A and B are expected to be sparse and of the size 10 000 x 10 000 (two big covariance matrices). I know that the inverse of a sparse matrix is not sparse in general (but I do not know then it is actually sparse). Should I use CUBLAS or CUSPARSE to solve the problem?

And yes I actually need to calculate the inverse for further calculations.

For a problem like this, consider using the dense matrix inversion routine (xGETRI) from a high-level linear algebra library like CULA.

Sparse inversion and multiplication are two tricky (and lower performance) problems especially since a 10k matrix isn’t that large.

Is anyway you can perform an LU or L’L factorization and reuse those factors? That would be the optimal solution.

Hope this helps!

Well I would like to work with sparse matrices that are of the size 18 000 000 x 18 000 000, but if the inverse is not also sparse there is no point. Therefore I want to start with “small” matrices.

Unfortunately, inverting a sparse matrix a big DON’T DO THAT! As far as I know no tools, even on the CPU even, exist to calculate a complete sparse matrix inverse.

To quote Tim Davis, the author of widely used sparse matrix tools: “Never invert a matrix, particularly a large sparse one.”