Skip to main content
`Ctrl`+`K`

# KSPSetNormType

Sets the type of residual norm that is used for convergence testing in `KSPSolve()` for the given `KSP` context

## Synopsis

    #include "petscksp.h"
    PetscErrorCode KSPSetNormType(KSP ksp, KSPNormType normtype)

Logically Collective

## Input Parameters

- ksp - Krylov solver context

- normtype - one of

       KSP_NORM_NONE             - skips computing the norm, this should generally only be used if you are using
                                   the Krylov method as a smoother with a fixed small number of iterations.
                                   Implicitly sets `KSPConvergedSkip()` as the `KSP` convergence test.
                                   Note that certain algorithms such as `KSPGMRES` ALWAYS require the norm calculation,
                                   for these methods the norms are still computed, they are just not used in
                                   the convergence test.
       KSP_NORM_PRECONDITIONED   - the default for left-preconditioned solves, uses the 2-norm
                                   of the preconditioned residual  $B^{-1}(b - A x)$.
       KSP_NORM_UNPRECONDITIONED - uses the 2-norm of the true $b - Ax$ residual.
       KSP_NORM_NATURAL          - uses the $A$ norm of the true $b - Ax$ residual; supported by `KSPCG`, `KSPCR`, `KSPCGNE`, `KSPCGS`

## Options Database Key

- -ksp_norm_type <none,preconditioned,unpreconditioned,natural> - set `KSP` norm type

## Notes

The norm is always of the equations residual \(\| b - A x^n \|\) (or an approximation to that norm), they are never a norm of the error in the equation.

Not all combinations of preconditioner side (see `KSPSetPCSide()`) and norm types are supported by all Krylov methods. If only one is set, PETSc tries to automatically change the other to find a compatible pair. If no such combination is supported, PETSc will generate an error.

## Developer Note

Supported combinations of norm and preconditioner side are set using `KSPSetSupportedNorm()` for each `KSPType`.

## See Also

KSP: Linear System Solvers, `KSPSetUp()`, `KSPSolve()`, `KSPDestroy()`, `KSPConvergedSkip()`, `KSPSetCheckNormIteration()`, `KSPSetPCSide()`, `KSPGetPCSide()`, `KSPNormType`

## Level

advanced

## Location

src/ksp/ksp/interface/itcreate.c

## Examples

src/ksp/pc/tutorials/ex4.c
src/ksp/ksp/tutorials/ex71.c
src/snes/tutorials/ex11.c

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