# TaoAppSetGradientRoutine

Sets the gradient evaluation routine for use by the TAO_APPLICATION routines.

## Synopsis

    #include "tao.h"
    int TaoAppSetGradientRoutine(TAO_APPLICATION taoapp, int (*grad)(TAO_APPLICATION,Vec,Vec,void*),void *ctx)

Collective on TAO_APPLICATION

## Input Parameters

| taoapp | - the TAO_APPLICATION context
| grad | - gradient evaluation routine
| ctx | - [optional] user-defined function context

## Calling sequence of func

        grad (TAO_APPLICATION taoapp,Vec x,Vec g,void *ctx);

| taoapp | - the TAO_APPLICATION context
| x | - input vector
| g | - gradient vector
| ctx | - user-defined function gradient context set from TaoAppSetGradientRoutine()

## Options Database Keys

-tao_view_gradient -view the gradient after each evaluation using PETSC_VIEWER_STDOUT_WORLD

## Note

In most cases, the routine TaoAppSetObjectiveAndGradientRoutine() is more appropriate. However, when using finite differences to compute the Hessian, setting this routine can be beneficial.

## Keywords

TAO_APPLICATION, set, gradient

## See Also

TaoAppGetGradientVec(), TaoAppSetObjectiveAndGradientRoutine(), TaoAppSetHessianRoutine()

Level:intermediate
Location:src/petsctao/application/petscapp/tao_app_fg.c
TAO Solver Index
Table of Contents