Sample Code in C++ to run Sparse Solvers

In this chapter I will show how one can use sparse solvers from C++. I assume that the sparse solvers as well as the optimized BLAS are already available as compiled libraries and the goal would be mere to use them from C++. Note that a sparse direct solver requires matrix reordering and to this end the METIS library may be also necessary.

The goal will be to create an universal driver that will read the sparse matrix in the Matrix Market format, calls the solver, checks the norm | Ax – b | and writes the solution vector in the Matrix Market format. The code is presented in /files/code/benchmark/.

The Matrix Market format has been created by NIST to facilitate the matrix exchange and many sparse matrices can be found in The University of Florida Sparse Matrix Collection. The Matrix Market format is pretty simple. For a sparse matrix this is basically a list of triples value i j: nonzero matrix values with the coordinates. Most systems (for example, Matlab, Mathematica, SciPy) support it.

We start by considering simple matrix classes in C++, then we employ it to run TAUCS and MUMPS, and finally we create the universal driver that theoretically could be used for any sparse solver.

I use Microsoft Visual C++ as the compiler in this chapter but I am working with GNU Make under Cygwin. Hence it should be relatively easy to modify makefiles for example to compile the code with gcc.

Next

Class Matrix
Class SparseMatrix
Sample code in C++ to run TAUCS
Sample code in C++ to run MUMPS
Class LinearSolver
  Class UMFPACK
  Class TAUCS
  Class MUMPS and PARDISO
  Gluing all together: LinearSolver::create
Sample driver to run a sparse solver


Comments are closed.