Sample code in C++ to run MUMPS

I assume that you have already read Sample code in C++ to run TAUCS. The goal in this section is to compare two codes to run different sparse solvers when the purpose of the code is actually quite similar.  We would like to develop a command line tool that will read a matrix and a right-hand side

run_mumps matrix rhs

in the Matrix Market format and then writes the solution of the system of linear equations in file rhs.solution also in the Matrix Market format.

The code is presented in run_mumps.cpp and is briefly explained below. It is assumed that you have already browsed the MUMPS documentation.

The first difference is that MUMPS does not have an equivalent of  taucs_linsolve and we will need more steps to run MUMPS (this will be similar to using of TAUCS low-level functions). Also MUMPS does not have a function for matrix-vector multiply and it is implemented before the main in the code.

1) The SparseMatrix mat is initialized from the file matrix (first argument in the command line). Here there is no difference with run_taucs.cpp, as the same class SparseMatrix is employed.

2a) It takes more efforts to set up MUMPS. On the other hand, it is not necessary to create a MUMPS matrix, for matrix will be passed as several arrays and the user is responsible for their memory management. The matrix storage is different from TAUCS, it is just three arrays to represent val, i, j.

2b) The SparseMatrix is iterated through all nonzero elements and they are copied into the three arrays for MUMPS. Finally the memory to keep SparseMatrix is freed up. In this case actually it might be simpler directly write val, i, j from the Matrix Market file to the three arrays.

3) The matrix is factorized.

4) The right hand side is read in Matrix rhs. Note that it can contain several vectors in the case when we need to solve the linear system several times with different right-hand sides. This is similar to step 3 in run_taucs.cpp with the difference that MUMPS overwrites rhs with the solution and it is necessary to make a copy to compute the norm.

5) Back substitution when the factor from the step 3 is employed to find a solution to  A x = rhs. x now is in rhs.

6) The norm | Ax - rhs | is computed and printed. After that the solution is saved into the file. This is similar to step 4c in run_taucs.cpp.

7) Clean up memory. This is similar to step 5 in TAUCS.

The compilation and testing is very similar to what is described in Sample code in C++ to run TAUCS and is left as an exercise. If you are in trouble, please just run

$ make -f run_mumps.make

and then look at what is in the makefile.


Class Matrix
Class SparseMatrix
Sample code in C++ to run TAUCS


Class LinearSolver
  Class TAUCS
  Gluing all together: LinearSolver::create
Sample driver to run a sparse solver

Comments are closed.