:orphan:
# KSPSetErrorHistory
Sets the array used to hold the error history. If set, this array will contain the error norms computed at each iteration of the solver. 
## Synopsis
```
#include "petscksp.h" 
#include "petscmat.h" 
PetscErrorCode KSPSetErrorHistory(KSP ksp, PetscReal a[], PetscInt na, PetscBool reset)
```
Not Collective


## Input Parameters

- ***ksp   -*** iterative context 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, the array 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' is `PETSC_DECIDE` or `PETSC_DEFAULT` then a default array of length 10000 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
 [](ch_ksp), `KSPGetErrorHistory()`, `KSPSetResidualHistory()`, `KSP`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/interface/itfunc.c.html#KSPSetErrorHistory">src/ksp/ksp/interface/itfunc.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/ksp/ksp/interface/itfunc.c)


[Index of all KSP routines](index.md)  
[Table of Contents for all manual pages](/manualpages/index.md)  
[Index of all manual pages](/manualpages/singleindex.md)  
