# KSPSetUp
Sets up the internal data structures for the later use of an iterative solver. 
## Synopsis
```
#include "petscksp.h" 
#include "petscmat.h" 
PetscErrorCode KSPSetUp(KSP ksp)
```
Collective


## Input Parameter

- ***ksp   -*** iterative context obtained from `KSPCreate()`





## See Also
 [](chapter_ksp), `KSPCreate()`, `KSPSolve()`, `KSPDestroy()`, `KSP`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/interface/itfunc.c.html#KSPSetUp">src/ksp/ksp/interface/itfunc.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/stag/tutorials/ex4.c.html">src/dm/impls/stag/tutorials/ex4.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/tutorials/ex1.c.html">src/ksp/pc/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/tutorials/ex2.c.html">src/ksp/pc/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex10.c.html">src/ksp/ksp/tutorials/ex10.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex27.c.html">src/ksp/ksp/tutorials/ex27.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex28.c.html">src/ksp/ksp/tutorials/ex28.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex29.c.html">src/ksp/ksp/tutorials/ex29.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex41.c.html">src/ksp/ksp/tutorials/ex41.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex43.c.html">src/ksp/ksp/tutorials/ex43.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex45f.F90.html">src/ksp/ksp/tutorials/ex45f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex5.c.html">src/ksp/ksp/tutorials/ex5.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/bcgs/bcgs.c.html#KSPSetUp_BCGS">KSPSetUp_BCGS in src/ksp/ksp/impls/bcgs/bcgs.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/bcgs/fbcgs/fbcgs.c.html#KSPSetUp_FBCGS">KSPSetUp_FBCGS in src/ksp/ksp/impls/bcgs/fbcgs/fbcgs.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/bcgs/fbcgsr/fbcgsr.c.html#KSPSetUp_FBCGSR">KSPSetUp_FBCGSR in src/ksp/ksp/impls/bcgs/fbcgsr/fbcgsr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/bcgs/pipebcgs/pipebcgs.c.html#KSPSetUp_PIPEBCGS">KSPSetUp_PIPEBCGS in src/ksp/ksp/impls/bcgs/pipebcgs/pipebcgs.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/bcgs/qmrcgs/qmrcgs.c.html#KSPSetUp_QMRCGS">KSPSetUp_QMRCGS in src/ksp/ksp/impls/bcgs/qmrcgs/qmrcgs.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/bcgsl/bcgsl.c.html#KSPSetUp_BCGSL">KSPSetUp_BCGSL in src/ksp/ksp/impls/bcgsl/bcgsl.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/bicg/bicg.c.html#KSPSetUp_BiCG">KSPSetUp_BiCG in src/ksp/ksp/impls/bicg/bicg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/cg.c.html#KSPSetUp_CG">KSPSetUp_CG in src/ksp/ksp/impls/cg/cg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/cgls.c.html#KSPSetUp_CGLS">KSPSetUp_CGLS in src/ksp/ksp/impls/cg/cgls.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/cgne/cgne.c.html#KSPSetUp_CGNE">KSPSetUp_CGNE in src/ksp/ksp/impls/cg/cgne/cgne.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/groppcg/groppcg.c.html#KSPSetUp_GROPPCG">KSPSetUp_GROPPCG in src/ksp/ksp/impls/cg/groppcg/groppcg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/pipecg/pipecg.c.html#KSPSetUp_PIPECG">KSPSetUp_PIPECG in src/ksp/ksp/impls/cg/pipecg/pipecg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/pipecg2/pipecg2.c.html#KSPSetUp_PIPECG2">KSPSetUp_PIPECG2 in src/ksp/ksp/impls/cg/pipecg2/pipecg2.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/pipecgrr/pipecgrr.c.html#KSPSetUp_PIPECGRR">KSPSetUp_PIPECGRR in src/ksp/ksp/impls/cg/pipecgrr/pipecgrr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/pipelcg/pipelcg.c.html#KSPSetUp_PIPELCG">KSPSetUp_PIPELCG in src/ksp/ksp/impls/cg/pipelcg/pipelcg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cg/pipeprcg/pipeprcg.c.html#KSPSetUp_PIPEPRCG">KSPSetUp_PIPEPRCG in src/ksp/ksp/impls/cg/pipeprcg/pipeprcg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cgs/cgs.c.html#KSPSetUp_CGS">KSPSetUp_CGS in src/ksp/ksp/impls/cgs/cgs.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cheby/cheby.c.html#KSPSetUp_Chebyshev">KSPSetUp_Chebyshev in src/ksp/ksp/impls/cheby/cheby.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cr/cr.c.html#KSPSetUp_CR">KSPSetUp_CR in src/ksp/ksp/impls/cr/cr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/cr/pipecr/pipecr.c.html#KSPSetUp_PIPECR">KSPSetUp_PIPECR in src/ksp/ksp/impls/cr/pipecr/pipecr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/fcg/fcg.c.html#KSPSetUp_FCG">KSPSetUp_FCG in src/ksp/ksp/impls/fcg/fcg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/fcg/pipefcg/pipefcg.c.html#KSPSetUp_PIPEFCG">KSPSetUp_PIPEFCG in src/ksp/ksp/impls/fcg/pipefcg/pipefcg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/fetidp/fetidp.c.html#KSPSetUp_FETIDP">KSPSetUp_FETIDP in src/ksp/ksp/impls/fetidp/fetidp.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gcr/gcr.c.html#KSPSetUp_GCR">KSPSetUp_GCR in src/ksp/ksp/impls/gcr/gcr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gcr/pipegcr/pipegcr.c.html#KSPSetUp_PIPEGCR">KSPSetUp_PIPEGCR in src/ksp/ksp/impls/gcr/pipegcr/pipegcr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/agmres/agmres.c.html#KSPSetUp_AGMRES">KSPSetUp_AGMRES in src/ksp/ksp/impls/gmres/agmres/agmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/dgmres/dgmres.c.html#KSPSetUp_DGMRES">KSPSetUp_DGMRES in src/ksp/ksp/impls/gmres/dgmres/dgmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/fgmres/fgmres.c.html#KSPSetUp_FGMRES">KSPSetUp_FGMRES in src/ksp/ksp/impls/gmres/fgmres/fgmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/gmres.c.html#KSPSetUp_GMRES">KSPSetUp_GMRES in src/ksp/ksp/impls/gmres/gmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/lgmres/lgmres.c.html#KSPSetUp_LGMRES">KSPSetUp_LGMRES in src/ksp/ksp/impls/gmres/lgmres/lgmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/pgmres/pgmres.c.html#KSPSetUp_PGMRES">KSPSetUp_PGMRES in src/ksp/ksp/impls/gmres/pgmres/pgmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/gmres/pipefgmres/pipefgmres.c.html#KSPSetUp_PIPEFGMRES">KSPSetUp_PIPEFGMRES in src/ksp/ksp/impls/gmres/pipefgmres/pipefgmres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/hpddm/hpddm.cxx.html#KSPSetUp_HPDDM">KSPSetUp_HPDDM in src/ksp/ksp/impls/hpddm/hpddm.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/ibcgs/ibcgs.c.html#KSPSetUp_IBCGS">KSPSetUp_IBCGS in src/ksp/ksp/impls/ibcgs/ibcgs.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/lcd/lcd.c.html#KSPSetUp_LCD">KSPSetUp_LCD in src/ksp/ksp/impls/lcd/lcd.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/lsqr/lsqr.c.html#KSPSetUp_LSQR">KSPSetUp_LSQR in src/ksp/ksp/impls/lsqr/lsqr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/minres/minres.c.html#KSPSetUp_MINRES">KSPSetUp_MINRES in src/ksp/ksp/impls/minres/minres.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/preonly/preonly.c.html#KSPSetUp_PREONLY">KSPSetUp_PREONLY in src/ksp/ksp/impls/preonly/preonly.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/qcg/qcg.c.html#KSPSetUp_QCG">KSPSetUp_QCG in src/ksp/ksp/impls/qcg/qcg.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/rich/rich.c.html#KSPSetUp_Richardson">KSPSetUp_Richardson in src/ksp/ksp/impls/rich/rich.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/symmlq/symmlq.c.html#KSPSetUp_SYMMLQ">KSPSetUp_SYMMLQ in src/ksp/ksp/impls/symmlq/symmlq.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/tcqmr/tcqmr.c.html#KSPSetUp_TCQMR">KSPSetUp_TCQMR in src/ksp/ksp/impls/tcqmr/tcqmr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/tfqmr/tfqmr.c.html#KSPSetUp_TFQMR">KSPSetUp_TFQMR in src/ksp/ksp/impls/tfqmr/tfqmr.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/impls/tsirm/tsirm.c.html#KSPSetUp_TSIRM">KSPSetUp_TSIRM in src/ksp/ksp/impls/tsirm/tsirm.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/ksp/ksp/interface/itfunc.c)


[Index of all KSP routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
