KSPSetResidualHistory — PETSc 3.24.5 documentation

Skip to main content
`Ctrl`+`K`

# KSPSetResidualHistory

Sets the array used to hold the residual history. If set, this array will contain the residual norms computed at each iteration of the solver.

## Synopsis

    #include "petscksp.h"
    #include "petscmat.h"
    PetscErrorCode KSPSetResidualHistory(KSP ksp, PetscReal a[], PetscCount na, PetscBool reset)

Not Collective

## Input Parameters

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

- a - array to hold history

- na - size of `a`

- reset - `PETSC_TRUE` indicates the history counter is reset to zero for each new linear solve

## Notes

If provided, `a` is NOT freed by PETSc so the user needs to keep track of it and destroy once the `KSP` object is destroyed. If ‘a’ is `NULL` then space is allocated for the history. If ‘na’ `PETSC_DECIDE` or (deprecated) `PETSC_DEFAULT` then a default array of length 10,000 is allocated.

If the array is not long enough then once the iterations is longer than the array length `KSPSolve()` stops recording the history

## See Also

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

## Level

advanced

## Location

src/ksp/ksp/interface/itfunc.c

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