Warning: This is no longer the latest available version of this module. Please see the releases page for the most recent version. The Webnucleo group strongly recommends the use of the latest version of any of its online modules.
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 104: WnSparseSolve__Mat__new()
- Line 106: WnSparseSolve__Mat__updateSolverMethod()
- Line 108: WnSparseSolve__Mat__updateMaximumIterations()
- Line 110: WnSparseSolve__Mat__updateRelativeTolerance()
- Line 112: WnSparseSolve__Mat__updateAbsoluteTolerance()
- Line 116: WnSparseSolve__Mat__setDebug()
- Line 126: WnSparseSolve__Mat__getSolverMethod()
- Line 134: WnSparseSolve__Mat__solve()
- Line 149: WnSparseSolve__Mat__free()
- Line 171: 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 106: WnSparseSolve__Mat__new()
- Line 108: WnSparseSolve__Mat__updateSolverMethod()
- Line 110: WnSparseSolve__Mat__updateMaximumIterations()
- Line 116: WnSparseSolve__Mat__updateConvergenceTester()
- Line 134: WnSparseSolve__Mat__updateConvergenceTesterUserData()
- Line 145: WnSparseSolve__Mat__setDebug()
- Line 155: WnSparseSolve__Mat__getSolverMethod()
- Line 163: WnSparseSolve__Mat__solve()
- Line 183: 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 128: WnSparseSolve__Mat__new()
- Line 130: WnSparseSolve__Mat__updateSolverMethod()
- Line 132: WnSparseSolve__Mat__updateMaximumIterations()
- Line 134: WnSparseSolve__Mat__updateRelativeTolerance()
- Line 136: WnSparseSolve__Mat__updateAbsoluteTolerance()
- Line 140: WnSparseSolve__Mat__setDebug()
- Line 147: WnSparseSolve__Mat__updatePreconditionerSolver()
- Line 152: WnSparseSolve__Mat__updatePreconditionerTransposeSolver()
- Line 158: WnSparseSolve__Mat__updatePreconditionerUserData()
- Line 167: WnSparseSolve__Mat__solve()
- Line 187: 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 113: WnSparseSolve__Mat__new()
- Line 115: WnSparseSolve__Mat__updateSolverMethod()
- Line 117: WnSparseSolve__Mat__updateMaximumIterations()
- Line 119: WnSparseSolve__Mat__updateRelativeTolerance()
- Line 121: WnSparseSolve__Mat__updateAbsoluteTolerance()
- Line 125: WnSparseSolve__Mat__setDebug()
- Line 132: WnSparseSolve__Mat__updatePreconditionerSolver()
- Line 137: WnSparseSolve__Mat__updatePreconditionerTransposeSolver()
- Line 145: WnSparseSolve__Mat__updatePreconditionerUserData()
- Line 154: WnSparseSolve__Mat__solve()
- Line 174: 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 109: WnSparseSolve__Exp__new()
- Line 115: WnSparseSolve__Exp__updateMaximumIterations()
- Line 117: WnSparseSolve__Exp__updateWorkSpace()
- Line 119: WnSparseSolve__Exp__updateTolerance()
- Line 127: WnSparseSolve__Exp__setDebug()
- Line 135: WnSparseSolve__Exp__solve()
- Line 149: 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 130: WnSparseSolve__Phi__new()
- Line 136: WnSparseSolve__Phi__updateMaximumIterations()
- Line 138: WnSparseSolve__Phi__updateWorkSpace()
- Line 140: WnSparseSolve__Phi__updateTolerance()
- Line 148: WnSparseSolve__Phi__setDebug()
- Line 156: WnSparseSolve__Phi__solve()
- Line 168: 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