# PetscOptionsGetenv
Gets an environmental variable, broadcasts to all processors in communicator from MPI rank zero 
## Synopsis
```
PetscErrorCode PetscOptionsGetenv(MPI_Comm comm, const char name[], char env[], size_t len, PetscBool *flag)
```
Collective


## Input Parameters

- ***comm -*** communicator to share variable
- ***name -*** name of environmental variable
- ***len -*** amount of space allocated to hold variable



## Output Parameters

- ***flag -*** if not NULL tells if variable found or not
- ***env -*** value of variable





## Notes
You can also "set" the environmental variable by setting the options database value
-name "stringvalue" (with name in lower case). If name begins with PETSC_ this is
discarded before checking the database. For example, `PETSC_VIEWER_SOCKET_PORT` would
be given as -viewer_socket_port 9000

If comm does not contain the 0th process in the MPIEXEC it is likely on
many systems that the environmental variable will not be set unless you
put it in a universal location like a .chsrc file


## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/utils/pdisplay.c.html#PetscOptionsGetenv">src/sys/utils/pdisplay.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/utils/pdisplay.c)


[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)  
