1. If the matrix is that small, it will be both faster and easier just
to use LAPACK to compute the inverse.
2. Usually the inverse of a sparse matrix is dense.
3. If you're doing quantum mechanical calculations, for which you
might need only some of the diagonal or off-diagonal entries of the
inverse, there are faster ways to compute the entries you want
(without computing the whole inverse).
mfh
There are language bindings like LAPACK++ and CLAPACK to help you with
that. Usually I just call LAPACK from Fortran (not 77, 2003).
Otherwise you'll have to observe the conventions that your particular
compiler follows regarding calling Fortran from C(++).
The LAPACK routine you want is xGETRI. Replace "x" in the routine
name with a letter corresponding to your data type: "S" for float,
"D" for double, "C" for complex float, "Z" for complex double.
In this archives of this mailing list are several examples for calling
LAPACK routines from C(++), as well as a link to an excellently
written tutorial.
> 2) Also, what is the most appropriate library to perform matrix-vector
> multiplication? I remember to have heard about BLAS, but I am not
> sure. I also need to do it in C++. I guess TAUCS can manage matrix-
> vector multiplication when the matrix is sparse.
It depends on what you mean by "appropriate." Do you mean "easy to
use," or "fast for typical workstations," or "fast for my more exotic
computing platform"? Does the sparse matrix-vector multiplication
dominate the cost of your computation?
> 3) Is LAPACK++ suitable for 2)?
LAPACK does not supply sparse routines. The BLAS does have a dense
matrix-vector multiply (xGEMV, where "x" again is a letter
corresponding to the data type).
mfh
> It depends on what you mean by "appropriate." Do you mean "easy to
> use," or "fast for typical workstations," or "fast for my more exotic
> computing platform"? Does the sparse matrix-vector multiplication
> dominate the cost of your computation?
Fast for typical workstations. No, it does not dominate. Even though, I
would like to know for both cases: a) when it does dominate and b) when it
does not dominate.
Thanks,
-a
Let me suggest, then, a library written by our research group:
http://bebop.cs.berkeley.edu/oski/
Note, however, that I am not responsible for maintaining this library,
so questions should be directed to the appropriate e-mail list. (It
_is_ being maintained, however, and pretty soon some neat features
like an automatically tuned shared-memory parallel A*x will be going
into it.)
You may also like to try the reference implementation of the Sparse
BLAS standard:
Note that it is a reference implementation, which means it won't be
tuned. However, it will still give you a sparse matrix-vector
multiply which requires only O(n+nnz) operations, where the matrix is
n by n and has nnz nonzeros.
Even if the sparse matrix-vector multiplications don't dominate your
application, you still want to make sure that they respect the storage
format used by your sparse matrix and don't do silly things like
converting it to dense.
Best,
mfh