petsc-3.7.1 2016-05-15
Report Typos and Errors

# KSPSolve

Solves linear system.

### Synopsis

    #include "petscksp.h"
    PetscErrorCode KSPSolve(KSP ksp,Vec b,Vec x)

Collective on KSP Many br

### Parameter

| ksp | - iterative context obtained from KSPCreate() Many br
| b | - the right hand side vector Many br
| x | - the solution (this may be the same vector as b, then b will be overwritten with answer) Many br

### Options Database Keys

| -ksp_compute_eigenvalues | - compute preconditioned operators eigenvalues Many br
| -ksp_plot_eigenvalues | - plot the computed eigenvalues in an X-window Many br
| -ksp_plot_eigencontours | - plot the computed eigenvalues in an X-window with contours Many br
| -ksp_compute_eigenvalues_explicitly | - compute the eigenvalues by forming the dense operator and using LAPACK Many br
| -ksp_plot_eigenvalues_explicitly | - plot the explicitly computing eigenvalues Many br
| -ksp_view_mat binary | - save matrix to the default binary viewer Many br
| -ksp_view_pmat binary | - save matrix used to build preconditioner to the default binary viewer Many br
| -ksp_view_rhs binary | - save right hand side vector to the default binary viewer Many br
| -ksp_view_solution binary | - save computed solution vector to the default binary viewer Many br(can be read later with src/ksp/examples/tutorials/ex10.c for testing solvers) Many br
| -ksp_view_mat_explicit | - for matrix-free operators, computes the matrix entries and views them Many br
| -ksp_view_preconditioned_operator_explicit | - computes the product of the preconditioner and matrix as an explicit matrix and views it Many br
| -ksp_converged_reason | - print reason for converged or diverged, also prints number of iterations Many br
| -ksp_final_residual | - print 2-norm of true linear system residual at the end of the solution process Many br
| -ksp_view | - print the ksp data structure at the end of the system solution Many br

### Notes

If one uses KSPSetDM() then x or b need not be passed. Use KSPGetSolution() to access the solution in this case. Many br

The operator is specified with KSPSetOperators(). Many br

Call KSPGetConvergedReason() to determine if the solver converged or failed and Many brwhy. The number of iterations can be obtained from KSPGetIterationNumber(). Many br

If using a direct method (e.g., via the KSP solver Many brKSPPREONLY and a preconditioner such as PCLU/PCILU), Many brthen its=1. See KSPSetTolerances() and KSPConvergedDefault() Many brfor more details. Many br

### Understanding Convergence

The routines KSPMonitorSet(), KSPComputeEigenvalues(), and Many brKSPComputeEigenvaluesExplicitly() provide information on additional Many broptions to monitor convergence and print eigenvalue information. Many br

Many br

### Keywords

KSP, solve, linear system

### See Also

KSPCreate(), KSPSetUp(), KSPDestroy(), KSPSetTolerances(), KSPConvergedDefault(),
KSPSolveTranspose(), KSPGetIterationNumber() Many br

Level:beginner
Location:src/ksp/ksp/interface/itfunc.c
Index of all KSP routines
Table of Contents for all manual pages
Index of all manual pages src/ksp/pc/examples/tutorials/ex1.c.html
src/ksp/pc/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex1.c.html
src/ksp/ksp/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex3.c.html
src/ksp/ksp/examples/tutorials/ex4.c.html
src/ksp/ksp/examples/tutorials/ex5.c.html
src/ksp/ksp/examples/tutorials/ex6.c.html
src/ksp/ksp/examples/tutorials/ex7.c.html
src/ksp/ksp/examples/tutorials/ex8.c.html