# KSPSetFromOptions#

Sets KSP options from the options database. This routine must be called before KSPSetUp() if the user is to be allowed to set the Krylov type.

## Synopsis#

```
#include "petscksp.h"
PetscErrorCode KSPSetFromOptions(KSP ksp)
```

Collective on ksp

## Input Parameter#

the Krylov space context**ksp -**

## Options Database Keys#

maximum number of linear iterations**-ksp_max_it -**relative tolerance used in default determination of convergence, i.e. if residual norm decreases by this factor than convergence is declared**-ksp_rtol rtol -**absolute tolerance used in default convergence test, i.e. if residual norm is less than this then convergence is declared**-ksp_atol abstol -**if residual norm increases by this factor than divergence is declared**-ksp_divtol tol -**see KSPConvergedDefaultSetUIRNorm()**-ksp_converged_use_initial_residual_norm -**see KSPConvergedDefaultSetUMIRNorm()**-ksp_converged_use_min_initial_residual_norm -**see KSPConvergedDefaultSetConvergedMaxits()**-ksp_converged_maxits -**none - skip norms used in convergence tests (useful only when not using convergence test (say you always want to run with 5 iterations) to save on communication overhead preconditioned - default for left preconditioning unpreconditioned - see KSPSetNormType() natural - see KSPSetNormType()**-ksp_norm_type -**do not compute residual norm until iteration number it (does compute at 0th iteration) works only for PCBCGS, PCIBCGS and and PCCG**-ksp_check_norm_iteration it -**compute the norm of the residual for the ith iteration on the i+1 iteration; this means that one can use the norm of the residual for convergence test WITHOUT an extra MPI_Allreduce() limiting global synchronizations. This will require 1 more iteration of the solver than usual.**-ksp_lag_norm -**Type of initial guess generator for repeated linear solves**-ksp_guess_type -**uses the Fischer initial guess generator for repeated linear solves**-ksp_fischer_guess <model,size> -**assume the operator (matrix) has the constant vector in its null space**-ksp_constant_null_space -**tests the null space set with MatSetNullSpace() to see if it truly is a null space**-ksp_test_null_space -**compute initial guess by applying the preconditioner to the right hand side**-ksp_knoll -**cancel all previous convergene monitor routines set**-ksp_monitor_cancel -**print residual norm at each iteration**-ksp_monitor -**plot residual norm at each iteration**-ksp_monitor draw::draw_lg -**print true residual norm at each iteration**-ksp_monitor_true_residual -**print residual norm at each iteration for ALL KSP solves, regardless of their prefix. This is useful for PCFIELDSPLIT, PCMG, etc that have inner solvers and you wish to track the convergence of all the solvers**-all_ksp_monitor**- plot solution at each iteration**-ksp_monitor_solution [ascii binary or draw][:filename][:format option] -**monitor extreme singular values at each iteration**-ksp_monitor_singular_value -**view the convergence state at the end of the solve**-ksp_converged_reason -**transpose the system explicitly in KSPSolveTranspose**-ksp_use_explicittranspose -**stop the program as soon as an error is detected in a KSPSolve(), KSP_DIVERGED_ITS is not treated as an error on inner KSPSolves**-ksp_error_if_not_converged -**view the convergence rate at the end of the solve**-ksp_converged_rate -**

## Notes#

To see all options, run your program with the -help option or consult Users-Manual: ch_ksp

## See Also#

`KSPSetOptionsPrefix()`

, `KSPResetFromOptions()`

, `KSPSetUseFischerGuess()`

## Level#

beginner

## Location#

## Examples#

src/dm/impls/swarm/tutorials/ex1.c.html

src/dm/impls/swarm/tutorials/ex1f90.F90.html

src/dm/impls/stag/tutorials/ex1.c.html

src/dm/impls/stag/tutorials/ex2.c.html

src/dm/impls/stag/tutorials/ex3.c.html

src/dm/impls/stag/tutorials/ex4.c.html

src/dm/impls/stag/tutorials/ex8.c.html

src/ksp/pc/tutorials/ex1.c.html

src/ksp/pc/tutorials/ex2.c.html

src/ksp/pc/tutorials/ex3.c.html

src/ksp/ksp/tutorials/ex100.c.html

## Implementations#

KSPSetFromOptions_BCGS in src/ksp/ksp/impls/bcgs/bcgs.c

{
KSPSetFromOptions_BCGSL in src/ksp/ksp/impls/bcgsl/bcgsl.c

{
KSPSetFromOptions_CG in src/ksp/ksp/impls/cg/cg.c

{
KSPSetFromOptions_PIPELCG in src/ksp/ksp/impls/cg/pipelcg/pipelcg.c

{
KSPSetFromOptions_PIPEPRCG in src/ksp/ksp/impls/cg/pipeprcg/pipeprcg.c

{
KSPSetFromOptions_Chebyshev in src/ksp/ksp/impls/cheby/cheby.c

{
KSPSetFromOptions_FCG in src/ksp/ksp/impls/fcg/fcg.c

{
KSPSetFromOptions_PIPEFCG in src/ksp/ksp/impls/fcg/pipefcg/pipefcg.c

{
KSPSetFromOptions_FETIDP in src/ksp/ksp/impls/fetidp/fetidp.c

{
KSPSetFromOptions_GCR in src/ksp/ksp/impls/gcr/gcr.c

{
KSPSetFromOptions_PIPEGCR in src/ksp/ksp/impls/gcr/pipegcr/pipegcr.c

{
KSPSetFromOptions_AGMRES in src/ksp/ksp/impls/gmres/agmres/agmres.c

{
KSPSetFromOptions_DGMRES in src/ksp/ksp/impls/gmres/dgmres/dgmres.c

{
KSPSetFromOptions_FGMRES in src/ksp/ksp/impls/gmres/fgmres/fgmres.c

{
KSPSetFromOptions_GMRES in src/ksp/ksp/impls/gmres/gmres.c

{
KSPSetFromOptions_LGMRES in src/ksp/ksp/impls/gmres/lgmres/lgmres.c

{
KSPSetFromOptions_PGMRES in src/ksp/ksp/impls/gmres/pgmres/pgmres.c

{
KSPSetFromOptions_PIPEFGMRES in src/ksp/ksp/impls/gmres/pipefgmres/pipefgmres.c

{
KSPSetFromOptions_HPDDM in src/ksp/ksp/impls/hpddm/hpddm.cxx

{
KSPSetFromOptions_LCD in src/ksp/ksp/impls/lcd/lcd.c

{
KSPSetFromOptions_LSQR in src/ksp/ksp/impls/lsqr/lsqr.c

{
KSPSetFromOptions_QCG in src/ksp/ksp/impls/qcg/qcg.c

{
KSPSetFromOptions_Richardson in src/ksp/ksp/impls/rich/rich.c

{
KSPSetFromOptions_TSIRM in src/ksp/ksp/impls/tsirm/tsirm.c

{

Index of all KSP routines

Table of Contents for all manual pages

Index of all manual pages