Skip to main content
`Ctrl`+`K`

# KSPSetConvergenceTest

Sets the function to be used to determine convergence of `KSPSolve()`

## Synopsis

    #include "petscksp.h"
    #include "petscmat.h"
    PetscErrorCode KSPSetConvergenceTest(KSP ksp, KSPConvergenceTestFn *converge, PetscCtx ctx, PetscCtxDestroyFn *destroy)

Logically Collective

## Input Parameters

- ksp - iterative solver obtained from `KSPCreate()`

- converge - pointer to the function, see `KSPConvergenceTestFn`

- ctx - context for private data for the convergence routine (may be `NULL`)

- destroy - a routine for destroying the context (may be `NULL`)

## Notes

Must be called after the `KSP` type has been set so put this after a call to `KSPSetType()`, or `KSPSetFromOptions()`.

The default convergence test, `KSPConvergedDefault()`, aborts if the residual grows to more than 10000 times the initial residual.

The default is a combination of relative and absolute tolerances. The residual value that is tested may be an approximation; routines that need exact values should compute them.

In the default PETSc convergence test, the precise values of reason are macros such as `KSP_CONVERGED_RTOL`, which are defined in petscksp.h.

## See Also

KSP: Linear System Solvers, `KSP`, `KSPConvergenceTestFn`, `KSPConvergedDefault()`, `KSPGetConvergenceContext()`, `KSPSetTolerances()`, `KSPGetConvergenceTest()`, `KSPGetAndClearConvergenceTest()`

## Level

advanced

## Location

src/ksp/ksp/interface/itfunc.c

## Examples

src/ksp/ksp/tutorials/ex57f.F90
src/ksp/ksp/tutorials/ex1f.F90
src/ksp/ksp/tutorials/ex2f.F90
src/ksp/ksp/tutorials/ex71.c

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