# KSPGetAndClearConvergenceTest
Gets the function to be used to determine convergence. Removes the current test without calling destroy on the test context 
## Synopsis
```
#include "petscksp.h" 
#include "petscmat.h" 
PetscErrorCode KSPGetAndClearConvergenceTest(KSP ksp, PetscErrorCode (**converge)(KSP, PetscInt, PetscReal, KSPConvergedReason *, void *), void **cctx, PetscErrorCode (**destroy)(void *))
```
Logically Collective


## Input Parameter

- ***ksp -*** iterative context obtained from `KSPCreate()`



## Output Parameters

- ***converge -*** pointer to convergence test function
- ***cctx    -*** context for private data for the convergence routine
- ***destroy -*** a routine for destroying the context



## Calling sequence of converge
```none
converge (`KSP` ksp, `PetscInt` it, `PetscReal` rnorm, `KSPConvergedReason` *reason,void *mctx)
```


- ***ksp -*** iterative context obtained from `KSPCreate()`
- ***it -*** iteration number
- ***rnorm -*** (estimated) 2-norm of (preconditioned) residual
- ***reason -*** the reason why it has converged or diverged
- ***cctx  -*** optional convergence context, as set by `KSPSetConvergenceTest()`





## Note
This is intended to be used to allow transferring the convergence test (and its context) to another testing object (for example another `KSP`) and then calling
`KSPSetConvergenceTest()` on this original `KSP`. If you just called `KSPGetConvergenceTest()` followed by `KSPSetConvergenceTest()` the original context information
would be destroyed and hence the transferred context would be invalid and trigger a crash on use


## See Also
 [](chapter_ksp), `KSP`, `KSPConvergedDefault()`, `KSPGetConvergenceContext()`, `KSPSetTolerances()`, `KSP`, `KSPSetConvergenceTest()`, `KSPGetConvergenceTest()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/interface/itfunc.c.html#KSPGetAndClearConvergenceTest">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](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
