Skip to main content
`Ctrl`+`K`

# KSPGetResidualHistory

Gets the array used to hold the residual history and the number of residuals it contains.

## Synopsis

    #include "petscksp.h"
    #include "petscmat.h"
    PetscErrorCode KSPGetResidualHistory(KSP ksp, const PetscReal *a[], PetscInt *na)

Not Collective

## Input Parameter

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

## Output Parameters

- a - pointer to array to hold history (or `NULL`)

- na - number of used entries in a (or `NULL`). Note this has different meanings depending on the `reset` argument to `KSPSetResidualHistory()`

## Note

This array is borrowed and should not be freed by the caller.

Can only be called after a `KSPSetResidualHistory()` otherwise `a` and `na` are set to `NULL` and zero

When `reset` was `PETSC_TRUE` since a residual is computed before the first iteration, the value of `na` is generally one more than the value returned with `KSPGetIterationNumber()`.

Some Krylov methods may not compute the final residual norm when convergence is declared because the maximum number of iterations allowed has been reached. In this situation, when `reset` was `PETSC_TRUE`, `na` will then equal the number of iterations reported with `KSPGetIterationNumber()`

Some Krylov methods (such as `KSPSTCG`), under certain circumstances, do not compute the final residual norm. In this situation, when `reset` was `PETSC_TRUE`, `na` will then equal the number of iterations reported with `KSPGetIterationNumber()`

`KSPBCGSL` does not record the residual norms for the “subiterations” hence the results from `KSPGetResidualHistory()` and `KSPGetIterationNumber()` will be different

## Fortran Note

Call `KSPRestoreResidualHistory()` when access to the history is no longer needed.

## See Also

KSP: Linear System Solvers, `KSPSetResidualHistory()`, `KSP`, `KSPGetIterationNumber()`, `KSPSTCG`, `KSPBCGSL`

## 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