# PetscDeviceContextGetCurrentContext
Get the current active `PetscDeviceContext` 
## Synopsis
```
#include <petscdevice.h> 
PetscErrorCode PetscDeviceContextGetCurrentContext(PetscDeviceContext *dctx)
```
Not Collective


## Output Parameter

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



## Notes
The user generally should not destroy contexts retrieved with this routine unless they
themselves have created them. There exists no protection against destroying the root
context.


## Developer Notes
Unless the user has set their own, this routine creates the "root" context the first time it
is called, registering its destructor to `PetscFinalize()`.




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

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/objects/device/interface/global_dcontext.cxx.html#PetscDeviceContextGetCurrentContext">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](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
