Skip to main content
`Ctrl`+`K`

# KSPSetPreSolve

Sets a function that is called at the beginning of each `KSPSolve()`. Used in conjunction with `KSPSetPostSolve()`.

## Synopsis

    #include "petscksp.h"
    PetscErrorCode KSPSetPreSolve(KSP ksp, KSPPSolveFn *presolve, void *ctx)

Logically Collective

## Input Parameters

- ksp - the solver object

- presolve - the function to call before the solve, see`KSPPSolveFn`

- ctx - an optional context needed by the function

## Notes

The function provided here `presolve` is used to modify the right hand side, and possibly the matrix, of the linear system to be solved. The function provided with `KSPSetPostSolve()` then modifies the resulting solution of that linear system to obtain the correct solution to the initial linear system.

The functions `PCPreSolve()` and `PCPostSolve()` provide a similar functionality and are used, for example with `PCEISENSTAT`.

## See Also

KSP: Linear System Solvers, `KSPPSolveFn`, `KSPSetUp()`, `KSPSolve()`, `KSPDestroy()`, `KSP`, `KSPSetPostSolve()`, `PCEISENSTAT`, `PCPreSolve()`, `PCPostSolve()`

## Level

developer

## Location

src/ksp/ksp/interface/itcreate.c

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