:orphan:
# DMLocalToGlobalHookAdd
adds a callback to be run when a local to global is called 
## Synopsis
```
#include "petscdm.h"          
#include "petscdmlabel.h"     
#include "petscds.h"     
PetscErrorCode DMLocalToGlobalHookAdd(DM dm, PetscErrorCode (*beginhook)(DM, Vec, InsertMode, Vec, void *), PetscErrorCode (*endhook)(DM, Vec, InsertMode, Vec, void *), void *ctx)
```
Logically Collective


## Input Parameters

- ***dm -*** the `DM`
- ***beginhook -*** function to run at the beginning of `DMLocalToGlobalBegin()`
- ***endhook -*** function to run after `DMLocalToGlobalEnd()` has completed
- ***ctx -*** [optional] user-defined context for provide data for the hooks (may be `NULL`)



## Calling sequence of `beginhook`
```none
PetscErrorCode  beginhook(DM fine, Vec l, InsertMode mode, Vec g, void *ctx)
```

- ***dm -*** global `DM`
- ***l -*** local vector
- ***mode -*** mode
- ***g -*** global vector
- ***ctx -*** optional user-defined function context



## Calling sequence of `endhook`
```none
PetscErrorCode  endhook(DM fine, Vec l, InsertMode mode, Vec g, void *ctx)
```

- ***global -*** global `DM`
- ***l -*** local vector
- ***mode -*** mode
- ***g -*** global vector
- ***ctx -*** optional user-defined function context





## See Also
 [](ch_dmbase), `DM`, `DMLocalToGlobal()`, `DMRefineHookAdd()`, `DMGlobalToLocalHookAdd()`, `SNESFASGetInterpolation()`, `SNESFASGetInjection()`, `PetscObjectCompose()`, `PetscContainerCreate()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/interface/dm.c.html#DMLocalToGlobalHookAdd">src/dm/interface/dm.c</A>


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


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