:orphan:
# PetscDeviceContextSetCurrentContext
Set the current active `PetscDeviceContext` 
## Synopsis
```
#include <petscdevice.h> 
PetscErrorCode PetscDeviceContextSetCurrentContext(PetscDeviceContext dctx)
```
Not Collective


## Input Parameter

- ***dctx -*** The `PetscDeviceContext`



## Notes
This routine can be used to set the defacto "root" `PetscDeviceContext` to a user-defined
implementation by calling this routine immediately after `PetscInitialize()` and ensuring that
`PetscDevice` is not greedily initialized. In this case the user is responsible for destroying
their `PetscDeviceContext` before `PetscFinalize()` returns.

The old context is not stored in any way by this routine; if one is overriding a context that
they themselves do not control, one should take care to temporarily store it by calling
`PetscDeviceContextGetCurrentContext()` before calling this routine.




## See Also
 `PetscDeviceContextGetCurrentContext()`, `PetscDeviceContextFork()`,
`PetscDeviceContextJoin()`, `PetscDeviceContextCreate()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/objects/device/interface/global_dcontext.cxx.html#PetscDeviceContextSetCurrentContext">src/sys/objects/device/interface/global_dcontext.cxx</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/objects/device/interface/global_dcontext.cxx)


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