This tutorial demonstrates how to use the example codes in the wn_sparse_solve distribution src/examples directory. The sample input files used in the tutorial are included in the distribution release and may be located in the data_pub directory.
Example 1: Solve a sparse matrix equation without preconditioning.
wn_sparse_solve routines demonstrated in example1.c are:
- Line 103: WnSparseSolve__Mat__new()
- Line 105: WnSparseSolve__Mat__updateSolverMethod()
- Line 107: WnSparseSolve__Mat__updateMaximumIterations()
- Line 109: WnSparseSolve__Mat__updateRelativeTolerance()
- Line 111: WnSparseSolve__Mat__updateAbsoluteTolerance()
- Line 115: WnSparseSolve__Mat__setDebug()
- Line 125: WnSparseSolve__Mat__getSolverMethod()
- Line 133: WnSparseSolve__Mat__solve()
- Line 148: WnSparseSolve__Mat__free()
- Line 170: WnSparseSolve__Mat__updateConvergenceMethod()
To run example1, type the following on the command line:
./example1 ../../data_pub/matrix.xml ../../data_pub/rhs.xml gmres 10 1.e-4 1.e-4 > ex1_output.txt
The result is ex1_output.txt
Try other solvers. For example, to use the biconjugate gradient solver instead of the gmres solver, type
./example1 ../../data_pub/matrix.xml ../../data_pub/rhs.xml bcg 10 1.e-4 1.e-4 > ex1_output_bcg.txt
The result is ex1_output_bcg.txt
In this example, and all subsequent ones, you can also print out information about the solution iterations. For example, type
./example1 ../../data_pub/matrix.xml ../../data_pub/rhs.xml bcg 10 1.e-4 1.e-4 debug > ex1_output_debug.txt
The result is ex1_output_debug.txt
Example 2: Solve a sparse matrix equation using a user-supplied convergence tester.
wn_sparse_solve routines demonstrated in example2.c are:
- Line 105: WnSparseSolve__Mat__new()
- Line 107: WnSparseSolve__Mat__updateSolverMethod()
- Line 109: WnSparseSolve__Mat__updateMaximumIterations()
- Line 115: WnSparseSolve__Mat__updateConvergenceTester()
- Line 133: WnSparseSolve__Mat__updateConvergenceTesterUserData()
- Line 144: WnSparseSolve__Mat__setDebug()
- Line 154: WnSparseSolve__Mat__getSolverMethod()
- Line 162: WnSparseSolve__Mat__solve()
- Line 182: WnSparseSolve__Mat__free()
To run example2, type the following on the command line:
./example2 ../../data_pub/matrix.xml ../../data_pub/rhs.xml bcg 20 1.e-4 1.e-4 > ex2_output.txt
The result is ex2_output.txt
Example 3: Solve a sparse matrix equation using a user-supplied preconditioner matrix.
wn_sparse_solve routines demonstrated in example3.c are:
- Line 127: WnSparseSolve__Mat__new()
- Line 129: WnSparseSolve__Mat__updateSolverMethod()
- Line 131: WnSparseSolve__Mat__updateMaximumIterations()
- Line 133: WnSparseSolve__Mat__updateRelativeTolerance()
- Line 135: WnSparseSolve__Mat__updateAbsoluteTolerance()
- Line 139: WnSparseSolve__Mat__setDebug()
- Line 146: WnSparseSolve__Mat__updatePreconditionerSolver()
- Line 151: WnSparseSolve__Mat__updatePreconditionerTransposeSolver()
- Line 157: WnSparseSolve__Mat__updatePreconditionerUserData()
- Line 166: WnSparseSolve__Mat__solve()
- Line 186: WnSparseSolve__Mat__free()
To run example3, type the following on the command line:
./example3 ../../data_pub/matrix.xml ../../data_pub/preconditioner.xml ../../data_pub/rhs.xml gmres 20 1.e-4 1.e-4 > ex3_output.txt
The result is ex3_output.txt
Example 4: Solve a sparse matrix equation using SPARSKIT's incomplete lu decompositon routines for the preconditioner solves.
wn_sparse_solve routines demonstrated in example4.c are:
- Line 112: WnSparseSolve__Mat__new()
- Line 114: WnSparseSolve__Mat__updateSolverMethod()
- Line 116: WnSparseSolve__Mat__updateMaximumIterations()
- Line 118: WnSparseSolve__Mat__updateRelativeTolerance()
- Line 120: WnSparseSolve__Mat__updateAbsoluteTolerance()
- Line 124: WnSparseSolve__Mat__setDebug()
- Line 131: WnSparseSolve__Mat__updatePreconditionerSolver()
- Line 136: WnSparseSolve__Mat__updatePreconditionerTransposeSolver()
- Line 144: WnSparseSolve__Mat__updatePreconditionerUserData()
- Line 153: WnSparseSolve__Mat__solve()
- Line 173: WnSparseSolve__Mat__free()
To run example4, type the following on the command line:
./example4 ../../data_pub/matrix.xml ../../data_pub/rhs.xml gmres 10 1.e-4 1.e-4 > ex4_output.txt
The result is ex4_output.txt
Example 5: Solve the linear matrix equation dY/dt = AY with Sparskit.
wn_sparse_solve routines demonstrated in example5.c are:
- Line 108: WnSparseSolve__Exp__new()
- Line 114: WnSparseSolve__Exp__updateMaximumIterations()
- Line 116: WnSparseSolve__Exp__updateWorkSpace()
- Line 118: WnSparseSolve__Exp__updateTolerance()
- Line 126: WnSparseSolve__Exp__setDebug()
- Line 134: WnSparseSolve__Exp__solve()
- Line 148: WnSparseSolve__Exp__free()
To run example5, type the following on the command line:
./example5 ../../data_pub/exp_matrix.xml ../../data_pub/exp_initial_vector.xml 1 10 20 1.e-4 > ex5_output.txt
The result is ex5_output.txt
Example 6: Solve the linear matrix equation dY/dt = AY + P with Sparskit.
wn_sparse_solve routines demonstrated in example6.c are:
- Line 129: WnSparseSolve__Phi__new()
- Line 135: WnSparseSolve__Phi__updateMaximumIterations()
- Line 137: WnSparseSolve__Phi__updateWorkSpace()
- Line 139: WnSparseSolve__Phi__updateTolerance()
- Line 147: WnSparseSolve__Phi__setDebug()
- Line 155: WnSparseSolve__Phi__solve()
- Line 167: WnSparseSolve__Phi__free()
To run example6, type the following on the command line:
./example6 ../../data_pub/phi_matrix.xml ../../data_pub/phi_initial_vector.xml ../../data_pub/phi_constant_vector.xml 1 10 20 1.e-4 > ex6_output.txt
The result is ex6_output.txt