Skip to main content
`Ctrl`+`K`

# KSP

Abstract PETSc object that manages the linear solves in PETSc (even those such as direct factorization-based solvers that do not use Krylov accelerators).

## Synopsis

    typedef struct _p_KSP *KSP;

## Notes

When a direct solver is used, but no Krylov solver is used, the `KSP` object is still used but with a `KSPType` of `KSPPREONLY` (or equivalently `KSPNONE`), meaning that only application of the preconditioner is used as the linear solver.

Use `KSPSetType()` or the options database key `-ksp_type` to set the specific Krylov solver algorithm to use with a given `KSP` object

The `PC` object is used to control preconditioners in PETSc.

`KSP` can also be used to solve some least squares problems (over or under-determined linear systems), using, for example, `KSPLSQR`, see `PETSCREGRESSORLINEAR` for additional methods that can be used to solve least squares problems and other linear regressions).

## See Also

Summary of Sparse Linear Solvers Available In PETSc, KSP: Linear System Solvers, `KSPCreate()`, `KSPSetType()`, `KSPType`, `SNES`, `TS`, `PC`, `KSP`, `KSPDestroy()`, `KSPCG`, `KSPGMRES`

## Level

beginner

## Location

include/petscksp.h

## Examples

src/ksp/ksp/tutorials/ex1.c
src/dm/impls/stag/tutorials/ex4.c
src/ksp/ksp/tutorials/ex100.c
src/dm/impls/stag/tutorials/ex1.c
src/dm/impls/swarm/tutorials/ex1f90.F90
src/dm/impls/stag/tutorials/ex2.c
src/ksp/ksp/tutorials/ex12.c
src/dm/impls/stag/tutorials/ex8.c
src/dm/impls/stag/tutorials/ex3.c
src/ksp/ksp/tutorials/ex11.c

## Implementations

_p_KSP in include/petsc/private/kspimpl.h
KSP_BCGS in src/ksp/ksp/impls/bcgs/bcgsimpl.h
KSP_BCGSL in src/ksp/ksp/impls/bcgsl/bcgslimpl.h
KSP_CG in src/ksp/ksp/impls/cg/cgimpl.h
KSP_CGLS in src/ksp/ksp/impls/cg/cgls.c
KSP_Chebyshev in src/ksp/ksp/impls/cheby/chebyshevimpl.h
KSP_FCG in src/ksp/ksp/impls/fcg/fcgimpl.h
KSP_PIPEFCG in src/ksp/ksp/impls/fcg/pipefcg/pipefcgimpl.h
KSP_FETIDPMon in src/ksp/ksp/impls/fetidp/fetidp.c
KSP_FETIDP in src/ksp/ksp/impls/fetidp/fetidp.c
KSP_GCR in src/ksp/ksp/impls/gcr/gcr.c
KSP_PIPEGCR in src/ksp/ksp/impls/gcr/pipegcr/pipegcrimpl.h
KSP_AGMRES in src/ksp/ksp/impls/gmres/agmres/agmresimpl.h
KSP_DGMRES in src/ksp/ksp/impls/gmres/dgmres/dgmresimpl.h
KSP_FGMRES in src/ksp/ksp/impls/gmres/fgmres/fgmresimpl.h
KSP_GMRES in src/ksp/ksp/impls/gmres/gmresimpl.h
KSP_LGMRES in src/ksp/ksp/impls/gmres/lgmres/lgmresimpl.h
KSP_PGMRES in src/ksp/ksp/impls/gmres/pgmres/pgmresimpl.h
KSP_PIPEFGMRES in src/ksp/ksp/impls/gmres/pipefgmres/pipefgmresimpl.h
KSP_LCD in src/ksp/ksp/impls/lcd/lcdimpl.h
KSP_LSQR in src/ksp/ksp/impls/lsqr/lsqr.c
KSP_MINRES in src/ksp/ksp/impls/minres/minres.c
KSP_QCG in src/ksp/ksp/impls/qcg/qcgimpl.h
KSP_Richardson in src/ksp/ksp/impls/rich/richardsonimpl.h
KSP_SYMMLQ in src/ksp/ksp/impls/symmlq/symmlq.c
KSP_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