# TaoLineSearchSetGradientRoutine
Sets the gradient evaluation routine for the line search 
## Synopsis
```
#include "petsctaolinesearch.h" 
PetscErrorCode TaoLineSearchSetGradientRoutine(TaoLineSearch ls, PetscErrorCode (*func)(TaoLineSearch ls, Vec x, Vec g, void *), void *ctx)
```
Logically Collective on TaoLineSearch


## Input Parameters

- ***ls -*** the TaoLineSearch context
- ***func -*** the gradient evaluation routine
- ***ctx -*** the (optional) user-defined context for private data



## Calling sequence of func
```none
func (TaoLinesearch ls, Vec x, Vec g, void *ctx);
```


- ***x -*** input vector
- ***g -*** gradient vector
- ***ctx (optional) user-*** defined context





## Note
Use this routine only if you want the line search gradient
evaluation routine to be different from the Tao's gradient
evaluation routine. If you use this routine you must also set
the line search function and/or function/gradient routine.


## Note
Some algorithms (lcl, gpcg) set their own gradient routine for the
line search, application programmers should be wary of overriding the
default gradient routine.


## See Also
 `TaoLineSearchCreate()`, `TaoLineSearchSetObjectiveRoutine()`, `TaoLineSearchSetObjectiveAndGradientRoutine()`, `TaoLineSearchUseTaoRoutines()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/linesearch/interface/taolinesearch.c.html#TaoLineSearchSetGradientRoutine">src/tao/linesearch/interface/taolinesearch.c</A>


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


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