Skip to main content
`Ctrl`+`K`

# KSPSetTolerances

Sets the relative, absolute, divergence, and maximum iteration tolerances used by the default `KSP` convergence testers.

## Synopsis

    #include "petscksp.h"
    #include "petscmat.h"
    PetscErrorCode KSPSetTolerances(KSP ksp, PetscReal rtol, PetscReal abstol, PetscReal dtol, PetscInt maxits)

Logically Collective

## Input Parameters

- ksp - the Krylov subspace context

- rtol - the relative convergence tolerance, relative decrease in the (possibly preconditioned) residual norm

- abstol - the absolute convergence tolerance absolute size of the (possibly preconditioned) residual norm

- dtol - the divergence tolerance, amount (possibly preconditioned) residual norm can increase before `KSPConvergedDefault()` concludes that the method is diverging

- maxits - maximum number of iterations to use

## Options Database Keys

- -ksp_atol abstol - Sets `abstol`

- -ksp_rtol rtol - Sets `rtol`

- -ksp_divtol dtol - Sets `dtol`

- -ksp_max_it maxits - Sets `maxits`

## Notes

The tolerances are with respect to a norm of the residual of the equation \( \| b - A x^n \|\), they do not directly use the error of the equation. The norm used depends on the `KSPNormType` that has been set with `KSPSetNormType()`, the default depends on the `KSPType` used.

All parameters must be non-negative.

Use `PETSC_CURRENT` to retain the current value of any of the parameters. The deprecated `PETSC_DEFAULT` also retains the current value (though the name is confusing).

Use `PETSC_DETERMINE` to use the default value for the given `KSP`. The default value is the value when the object’s type is set.

For `dtol` and `maxits` use `PETSC_UNLIMITED` to indicate there is no upper bound on these values

See `KSPConvergedDefault()` for details how these parameters are used in the default convergence test. See also `KSPSetConvergenceTest()` for setting user-defined stopping criteria.

## Fortran Note

Use `PETSC_CURRENT_INTEGER`, `PETSC_CURRENT_REAL`, `PETSC_DETERMINE_INTEGER`, or `PETSC_DETERMINE_REAL`

## See Also

KSP: Linear System Solvers, `KSPGetTolerances()`, `KSPConvergedDefault()`, `KSPSetConvergenceTest()`, `KSP`, `KSPSetMinimumIterations()`

## Level

intermediate

## Location

src/ksp/ksp/interface/itfunc.c

## Examples

src/ksp/ksp/tutorials/ex1.c
src/ksp/ksp/tutorials/ex15.c
src/ksp/ksp/tutorials/ex18.c
src/ksp/ksp/tutorials/ex8.c
src/ksp/ksp/tutorials/ex62.c
src/ksp/ksp/tutorials/ex23.c
src/ksp/ksp/tutorials/ex86.c
src/ksp/ksp/tutorials/ex15f.F90
src/ksp/ksp/tutorials/ex71.c
src/ksp/ksp/tutorials/ex4.c

Index of all KSP routines
Table of Contents for all manual pages
Index of all manual pages