:orphan:
# SNESSetLagJacobian
Set when the Jacobian is rebuilt in the nonlinear solve. See `SNESSetLagPreconditioner()` for determining how often the preconditioner is rebuilt. 
## Synopsis
```
#include "petscsnes.h"  
PetscErrorCode SNESSetLagJacobian(SNES snes, PetscInt lag)
```
Logically Collective


## Input Parameters

- ***snes -*** the `SNES` context
- ***lag -*** -1 indicates NEVER rebuild, 1 means rebuild every time the Jacobian is computed within a single nonlinear solve, 2 means every second time
the Jacobian is built etc. -2 means rebuild at next chance but then never again



## Options Database Keys

- ***-snes_lag_jacobian_persists <true,false> -*** sets the persistence through multiple SNES solves
- ***-snes_lag_jacobian <-*** 2,1,2,...> - sets the lag
- ***-snes_lag_preconditioner_persists <true,false> -*** sets the persistence through multiple SNES solves
- ***-snes_lag_preconditioner <-*** 2,1,2,...> - sets the lag.





## Notes
The default is 1

The Jacobian is ALWAYS built in the first iteration of a nonlinear solve unless lag is -1

If  -1 is used before the very first nonlinear solve the CODE WILL FAIL! because no Jacobian is used, use -2 to indicate you want it recomputed
at the next Newton step but never again (unless it is reset to another value)


## See Also
 [](ch_snes), `SNES`, `SNESSetTrustRegionTolerance()`, `SNESGetLagPreconditioner()`, `SNESSetLagPreconditioner()`, `SNESGetLagJacobianPersists()`, `SNESSetLagPreconditionerPersists()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/interface/snes.c.html#SNESSetLagJacobian">src/snes/interface/snes.c</A>


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


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