Skip to main content
`Ctrl`+`K`

# VecSetValue

Set a single entry into a PETSc vector, `Vec`.

## Synopsis

    static inline PetscErrorCode VecSetValue(Vec v, PetscInt i, PetscScalar va, InsertMode mode)

Not Collective

## Input Parameters

- v - the vector

- row - the row location of the entry

- value - the value to insert

- mode - either `INSERT_VALUES` or `ADD_VALUES`

## Notes

For efficiency one should use `VecSetValues()` and set several or many values simultaneously if possible.

These values may be cached, so `VecAssemblyBegin()` and `VecAssemblyEnd()` MUST be called after all calls to `VecSetValue()` have been completed.

`VecSetValue()` uses 0-based indices in Python, C, and Fortran

## See Also

Vectors and Parallel Data, `VecSetValues()`, `VecAssemblyBegin()`, `VecAssemblyEnd()`, `VecSetValuesBlockedLocal()`, `VecSetValueLocal()`

## Level

beginner

## Location

include/petscvec.h

## Examples

src/tao/constrained/tutorials/ex1.c
src/snes/tutorials/ex28.c
src/ksp/ksp/tutorials/ex49.c
src/ksp/ksp/tutorials/ex43.c
src/snes/tutorials/ex70.c
src/mat/tutorials/ex3.c
src/snes/tutorials/ex56.c
src/ksp/ksp/tutorials/ex56.c
src/snes/tutorials/ex30.c
src/tao/unconstrained/tutorials/eptorsion3.c

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