# VecGetSubVector
Gets a vector representing part of another vector 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecGetSubVector(Vec X, IS is, Vec *Y)
```
Collective


## Input Parameters

- ***X -*** vector from which to extract a subvector
- ***is -*** index set representing portion of X to extract



## Output Parameter

- ***Y -*** subvector corresponding to is





## Notes
The subvector `Y` should be returned with `VecRestoreSubVector()`.
`X` and must be defined on the same communicator

This function may return a subvector without making a copy, therefore it is not safe to use the original vector while
modifying the subvector.  Other non-overlapping subvectors can still be obtained from X using this function.
The resulting subvector inherits the block size from the IS if greater than one. Otherwise, the block size is guessed from the block size of the original vec.


## See Also
 [](chapter_vectors), `Vec`, `IS`, `VECNEST`, `MatCreateSubMatrix()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/interface/rvector.c.html#VecGetSubVector">src/vec/vec/interface/rvector.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex44.c.html">src/vec/vec/tutorials/ex44.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex22.c.html">src/dm/tutorials/ex22.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex81.c.html">src/ksp/ksp/tutorials/ex81.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex63.c.html">src/snes/tutorials/ex63.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex70.c.html">src/snes/tutorials/ex70.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex77.c.html">src/ts/tutorials/ex77.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/kokkos/mpikok.kokkos.cxx.html#VecGetSubVector_MPIKokkos">VecGetSubVector_MPIKokkos in src/vec/vec/impls/mpi/kokkos/mpikok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/nest/vecnest.c.html#VecGetSubVector_Nest">VecGetSubVector_Nest in src/vec/vec/impls/nest/vecnest.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx.html#VecGetSubVector_SeqKokkos">VecGetSubVector_SeqKokkos in src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/vec/vec/interface/rvector.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)  
