|
|
# Solve the Matrix stored in mtx format
|
|
|
|
|
|
The code for this example is located in `examples/MatSolve`
|
|
|
|
|
|
## Brief
|
|
|
|
|
|
This example solves the linear system using different solvers.
|
|
|
|
|
|
## Description
|
|
|
This example may run in both serial and parallel modes with `NP` processes.
|
|
|
|
|
|
The code loads the matrix and right-hand side from files. If right-hand side is omitted, the artificial _rhs_=(1,1,...,1) is used. The specific solver is defined by user. User may also provide options file to alter default solver options.
|
|
|
|
|
|
## Arguments
|
|
|
```
|
|
|
Usage: ./MatSolve method_number<0:INNER_ILU2,1:INNER_MLILUC,2:PETSc,3:Trilinos_Aztec,4:Trilinos_Belos,5:Trilinos_Ifpack,6:Trilinos_ML,7:ANI> matrix.mtx [right_hand_side.rhs] [solver_options.txt]
|
|
|
```
|
|
|
- First parameter is the Solver type:
|
|
|
+ 0 – `INNER_ILU2`, inner Solver based on BiCGStab(L) solver with second order ILU factorization as preconditioner;
|
|
|
+ 1 – `INNER_MLILUC`, inner Solver based on BiCGStab(L) solver with second order Crout-ILU with inversed-based condition estimation and unsymmetric reordering for diagonal dominance as preconditioner;
|
|
|
+ 2 – `PETSc`, external Solver AztecOO from Trilinos package;
|
|
|
+ 3 – `Trilinos_Aztec`, external Solver Belos from Trilinos package, currently without preconditioner;
|
|
|
+ 4 – `Trilinos_Belos`, external Solver AztecOO with ML preconditioner;
|
|
|
+ 5 – `Trilinos_Ifpack`, external Solver AztecOO with Ifpack preconditioner;
|
|
|
+ 6 – `Trilinos_ML`, external Solver PETSc;
|
|
|
+ 7 – `ANI`, external Solver from ANI3D based on ILU2 (sequential Fortran version).
|
|
|
- Second parameter is the file with matrix in mtx format.
|
|
|
- Third optional parameter is the file with right-hand side in mtx format.
|
|
|
- Fourth optional parameter is the file with solver parameters, see `examples/MatSolve/database.txt` as example.
|
|
|
|
|
|
## Running example
|
|
|
You can generate matrices using [[FVDiscr|1710-FVDiscr-Example]] example. The following line uses matrix `/tmp/A.mtx` and right-hand side `/tmp/b.rhs` from [[FVDiscr example|1710-FVDiscr-Example#running-example]].
|
|
|
```
|
|
|
$ cd examples/MatSolve
|
|
|
$ mpirun -np 4 ./MatSolve 0 /tmp/A.mtx /tmp/b.rhs
|
|
|
load matrix: 0.346156
|
|
|
load vector: 0.0542159
|
|
|
preconditioner: 0.516358
|
|
|
solver: 0.0345631.37095e-06 | 0
|
|
|
||Ax-b|| 1.37095e-06 ||b|| 2.14884 ||Ax-b||/||b|| 6.37997e-07
|
|
|
norms: 0.00276518
|
|
|
4 processors solved in 0.95183 secs with 4 iterations to 1.37095e-06 norm matrix "/tmp/A.mtx" vector "/tmp/b.rhs" true residual ||Ax-b||/||b|| 6.37997e-07
|
|
|
reason: converged due to relative tolerance
|
|
|
``` |