# VecGhostGetLocalForm
Obtains the local ghosted representation of a parallel vector (obtained with VecCreateGhost(), VecCreateGhostWithArray() or VecCreateSeq()). Returns NULL if the Vec is not ghosted. 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecGhostGetLocalForm(Vec g, Vec *l)
```
Logically Collective


## Input Parameter

- ***g -*** the global vector



## Output Parameter

- ***l -*** the local (ghosted) representation, NULL if g is not ghosted



## Notes
This routine does not actually update the ghost values, but rather it
returns a sequential vector that includes the locations for the ghost
values and their current values. The returned vector and the original
vector passed in share the same array that contains the actual vector data.

To update the ghost values from the locations on the other processes one must call
VecGhostUpdateBegin() and VecGhostUpdateEnd() before accessing the ghost values. Thus normal
usage is
```none
VecGhostUpdateBegin(x,INSERT_VALUES,SCATTER_FORWARD);
```
```none
VecGhostUpdateEnd(x,INSERT_VALUES,SCATTER_FORWARD);
```
```none
VecGhostGetLocalForm(x,&xlocal);
```
```none
VecGetArray(xlocal,&xvalues);
```
```none
// access the non-ghost values in locations xvalues[0:n-1] and ghost values in locations xvalues[n:n+nghost];
```
```none
VecRestoreArray(xlocal,&xvalues);
```
```none
VecGhostRestoreLocalForm(x,&xlocal);
```

One should call VecGhostRestoreLocalForm() or VecDestroy() once one is
finished using the object.




## See Also
 `VecCreateGhost()`, `VecGhostRestoreLocalForm()`, `VecCreateGhostWithArray()`


## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/commonmpvec.c.html#VecGhostGetLocalForm">src/vec/vec/impls/mpi/commonmpvec.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex14f.F90.html">src/vec/vec/tutorials/ex14f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex9.c.html">src/vec/vec/tutorials/ex9.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex9f.F90.html">src/vec/vec/tutorials/ex9f.F90.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/vec/vec/impls/mpi/commonmpvec.c)


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