Skip to main content
`Ctrl`+`K`

# VecPlaceArray

Allows one to replace the array in a vector with an array provided by the user. This is useful to avoid copying an array into a vector.

## Synopsis

    #include "petscvec.h"
    PetscErrorCode VecPlaceArray(Vec vec, const PetscScalar array[])

Logically Collective

## Input Parameters

- vec - the vector

- array - the array

## Notes

Adding `const` to `array` was an oversight, as subsequent operations on `vec` would likely modify the data in `array`. However, we have kept it to avoid breaking APIs.

Use `VecReplaceArray()` instead to permanently replace the array

You can return to the original array with a call to `VecResetArray()`. `vec` does not take ownership of `array` in any way.

The user must free `array` themselves but be careful not to do so before the vector has either been destroyed, had its original array restored with `VecResetArray()` or permanently replaced with `VecReplaceArray()`.

## See Also

Vectors and Parallel Data, `Vec`, `VecGetArray()`, `VecRestoreArray()`, `VecReplaceArray()`, `VecResetArray()`

## Level

developer

## Location

src/vec/vec/interface/rvector.c

## Examples

src/ksp/ksp/tutorials/ex13f90.F90
src/ksp/ksp/tutorials/ex61f.F90
src/ksp/ksp/tutorials/ex13.c

## Implementations

VecPlaceArray_MPI() in src/vec/vec/impls/mpi/pbvec.c
VecPlaceArray_Seq() in src/vec/vec/impls/seq/dvec2.c
VecPlaceArray_SeqKokkos() in src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx
VecPlaceArray_SeqViennaCL() in src/vec/vec/impls/seq/seqviennacl/vecviennacl.cxx

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