VecGetSubVector — PETSc 3.22.5 documentation

Skip to main content
`Ctrl`+`K`

# 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 `is` must be defined on the same communicator

Changes to the subvector will be reflected in the `X` vector on the call to `VecRestoreSubVector()`.

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 `is` if greater than one. Otherwise, the block size is guessed from the block size of the original `X`.

## See Also

Vectors and Parallel Data, `Vec`, `IS`, `VECNEST`, `MatCreateSubMatrix()`

## Level

advanced

## Location

src/vec/vec/interface/rvector.c

## Examples

src/ts/tutorials/ex77.c
src/ksp/ksp/tutorials/ex81.c
src/dm/tutorials/ex22.c
src/snes/tutorials/ex70.c
src/snes/tutorials/ex63.c
src/ksp/ksp/tutorials/ex81a.c
src/vec/vec/tutorials/ex44.c

## Implementations

VecGetSubVector_MPIKokkos() in src/vec/vec/impls/mpi/kokkos/mpikok.kokkos.cxx
VecGetSubVector_Nest() in src/vec/vec/impls/nest/vecnest.c
VecGetSubVector_SeqKokkos() in src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx

Index of all Vec routines
Table of Contents for all manual pages
Index of all manual pages