Skip to main content
`Ctrl`+`K`

# KSPBuildResidual

Builds the residual in a vector provided.

## Synopsis

    #include "petscksp.h"
    #include "petscmat.h"
    PetscErrorCode KSPBuildResidual(KSP ksp, Vec t, Vec v, Vec *V)

Collective

## Input Parameter

- ksp - iterative solver obtained from `KSPCreate()`

## Output Parameters

- t - work vector. If not provided then one is generated.

- v - optional location to stash residual. If `v` is not provided, then a location is generated.

- V - the residual

## Note

Regardless of whether or not `v` is provided, the residual is returned in `V`.

## See Also

KSP: Linear System Solvers, `KSP`, `KSPBuildSolution()`

## Level

advanced

## Location

src/ksp/ksp/interface/itfunc.c

## Examples

src/ts/tutorials/ex47.c
src/ksp/ksp/tutorials/ex42.c

## Implementations

KSPBuildResidual_CG() in src/ksp/ksp/impls/cg/cg.c
KSPBuildResidual_GCR() in src/ksp/ksp/impls/gcr/gcr.c
KSPBuildResidual_Richardson() in src/ksp/ksp/impls/rich/rich.c

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