Skip to main content
`Ctrl`+`K`

# KSPSetErrorIfNotConverged

Causes `KSPSolve()` to generate an error if the solver has not converged as soon as the error is detected.

## Synopsis

    #include "petscksp.h"
    #include "petscmat.h"
    PetscErrorCode KSPSetErrorIfNotConverged(KSP ksp, PetscBool flg)

Logically Collective

## Input Parameters

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

- flg - `PETSC_TRUE` indicates you want the error generated

## Options Database Key

- -ksp_error_if_not_converged <true,false> - generate an error and stop the program

## Notes

Normally PETSc continues if a linear solver fails to converge, you can call `KSPGetConvergedReason()` after a `KSPSolve()` to determine if it has converged. This functionality is mostly helpful while running in a debugger (`-start_in_debugger`) to determine exactly where the failure occurs and why.

A `KSP_DIVERGED_ITS` will not generate an error in a `KSPSolve()` inside a nested linear solver

## See Also

KSP: Linear System Solvers, `KSPGetErrorIfNotConverged()`, `KSP`

## Level

intermediate

## Location

src/ksp/ksp/interface/itfunc.c

## Examples

src/ksp/ksp/tutorials/ex89f.F90
src/ksp/ksp/tutorials/ex88f.F90
src/ksp/ksp/tutorials/bench_kspsolve.c
src/ksp/ksp/tutorials/ex83f.F90

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