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.

Previous

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

Next

Class LinearSolver
  Class UMFPACK
  Class TAUCS
  Class MUMPS and PARDISO
  Gluing all together: LinearSolver::create
Sample driver to run a sparse solver


Comments

3 responses to “Sample code in C++ to run MUMPS”

Comments are now closed
  1. Domen says:

    Dear Evgenii,

    i have downloaded MUMPS 4.10 and the latest winMumps project. I have created Visual Studio 2005 projects for compiling MUMPS libraries. For compiling i was using MSVC 9 and Intel Visual Fortran Compiler XE 12.1. Then I downloaded your files auxiliary.h, matrices.cpp, matrices.h and run_mumps.cpp. In the directory where i have run_mumps.cpp i have additional direrctories /headers and /LinearSolver. Directory /headers contains all the headers from MUMPS_4.10.0/include dir. Directory /LinearSolver contains auxiliary.h, matrices.h and matrices.cpp. I copied libraries dmumps_c.lib, dmumps_fortran.lib, libseq_c.lib, libseq_fortran.lib, pord_c.lib and mumps_common_c.lib from /MUMPS_4.10.0/lib/Debug/Win32 dir to the directory containing run_mumps.cpp. Additional needed libraries i copied from the Taucs distribution (libatla.lib, libcblas.lib, libf77blas.lib, liblapack.lib, libmetis.lib). To compile run_mumps.cpp i used msvc 9 compiler through Visual Studio 2008 Command Prompt. First i executed command vsvars32.bat. Afterwards i moved to the dir containing run_mumps.cpp. In this file i changed #include “*.h”to #include “headers/*.h”. I used next command for compilation:
    cl -I headers -I LinearSolver -O2 -EHsc -MD -D_SECURE_SCL=0 -c run_mumps.cpp
    cl -I LinearSolver -O2 -EHsc -MD -D_SECURE_SCL=0 -c LinearSolver/matrices.cpp
    cl run_mumps.obj matrices.obj dmumps_c.lib mumps_common_c.lib libmetis.lib libseq_c.lib liblapack.lib libf77blas.lib libcblas.lib libatlas.lib /link /NODEFAULTLIB:MSVCRTD

    Compilation of run_mumps.obj and matrices.obj executes fine without error. Compilation of run_mumps.exe returns: dmumps_c.lib(mumps_c.obj) LNK2019 error: unresolved external symbol _DMUMPS_F77 referenced in function _dmumps_c.

    If i use dmumps_fortran.lib and libseq_fortran.lib insted of dmumps_c.lib and libseq_c.lib i get similar error:
    run_mumps.obj: error LNK 2019: unresolved external symbol _dmumps_c referenced in function _main.

    Could you please provide me te solution to remove this error? Or maybe you would be so kind to e-mail me the whole VS 2008 solution for this project or maybe only the copiled version of run_mumps.exe?

    Best regars
    Domen Stadler

  2. My makefile to compile run_mumps is here

    http://matrixprogramming.com/files/code/benchmark/run_mumps.make

    I do it from the command line and do not use VS projects. I should say that I stay at MUMPS version 4.9.2 and I do not know where your MUMPS libraries come from. I have never used WinMUMPS, but when I compile MUMPS from the command line I have different libraries

    http://matrixprogramming.com/2010/05/mumps

    You can use nm to troubleshoot your linking problems

    http://matrixprogramming.com/2011/03/using-nm-to-troubleshoot-linking-problems

  3. Domen says:

    Dear Evgenii,

    i already solved the problem. Solution was to link both c and fortran version of libraries (for example dmumps_c.lib and dmumps_fortran.lib).
    Anyway thank you for your answer. When i will be finished with my code, i will try to post all my steps, so that other people could do the same.

    Best regards
    Domen Stadler