KSPGetResidualHistory — PETSc 3.22.5 documentation

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

The Fortran version of this routine has a calling sequence

      call KSPGetResidualHistory(KSP ksp, integer na, integer ierr)

note that you have passed a Fortran array into `KSPSetResidualHistory()` and you need to access the residual values from this Fortran array you provided. Only the `na` (number of residual norms currently held) is set.

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