:orphan:
# KSPSetPreSolve
Sets a function that is called at the beginning of each `KSPSolve()` 
## Synopsis
```
#include "petscksp.h" 
PetscErrorCode KSPSetPreSolve(KSP ksp, PetscErrorCode (*presolve)(KSP, Vec, Vec, void *), void *prectx)
```
Logically Collective


## Input Parameters

- ***ksp -*** the solver object
- ***presolve -*** the function to call before the solve
- ***prectx -*** any context needed by the function



## Calling sequence of `presolve`
```none
PetscErrorCode func(KSP ksp, Vec rhs, Vec x, void *ctx)
```

- ***ksp -*** the `KSP` context
- ***rhs -*** the right-hand side vector
- ***x -*** the solution vector
- ***ctx -*** optional user-provided context





## See Also
 `KSPSetUp()`, `KSPSolve()`, `KSPDestroy()`, `KSP`, `KSPSetPostSolve()`, `PCEISENSTAT`

## Level
developer

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


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


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