# VecSetValues
Inserts or adds values into certain locations of a vector. 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecSetValues(Vec x, PetscInt ni, const PetscInt ix[], const PetscScalar y[], InsertMode iora)
```
Not Collective


## Input Parameters

- ***x -*** vector to insert in
- ***ni -*** number of elements to add
- ***ix -*** indices where to add
- ***y -*** array of values
- ***iora -*** either INSERT_VALUES or ADD_VALUES, where
ADD_VALUES adds values to any existing entries, and
INSERT_VALUES replaces existing entries with new values



## Notes
VecSetValues() sets x[ix[i]] = y[i], for i=0,...,ni-1.

Calls to VecSetValues() with the INSERT_VALUES and ADD_VALUES
options cannot be mixed without intervening calls to the assembly
routines.

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

VecSetValues() uses 0-based indices in Fortran as well as in C.

If you call VecSetOption(x, VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE),
negative indices may be passed in ix. These rows are
simply ignored. This allows easily inserting element load matrices
with homogeneous Dirchlet boundary conditions that you don't want represented
in the vector.




## See Also
 `VecAssemblyBegin()`, `VecAssemblyEnd()`, `VecSetValuesLocal()`,
`VecSetValue()`, `VecSetValuesBlocked()`, `InsertMode`, `INSERT_VALUES`, `ADD_VALUES`, `VecGetValues()`

## Level
beginner

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex10.c.html">src/vec/vec/tutorials/ex10.c.html</A><BR>
<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/ex15.c.html">src/vec/vec/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex16.c.html">src/vec/vec/tutorials/ex16.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex16f.F90.html">src/vec/vec/tutorials/ex16f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex18.c.html">src/vec/vec/tutorials/ex18.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex18f.F90.html">src/vec/vec/tutorials/ex18f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex2.c.html">src/vec/vec/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex2f.F90.html">src/vec/vec/tutorials/ex2f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex3.c.html">src/vec/vec/tutorials/ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex3f.F90.html">src/vec/vec/tutorials/ex3f.F90.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/pdvec.c.html#VecSetValues_MPI">VecSetValues_MPI in src/vec/vec/impls/mpi/pdvec.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/bvec2.c.html#VecSetValues_Seq">VecSetValues_Seq in src/vec/vec/impls/seq/bvec2.c</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)  
