# MatSetValues

Inserts or adds a block of values into a matrix. These values may be cached, so MatAssemblyBegin() and MatAssemblyEnd() MUST be called after all calls to MatSetValues() have been completed.

### Synopsis

    #include "petscmat.h"
    int MatSetValues(Mat mat,int m,const int idxm[],int n,const int idxn[],const PetscScalar v[],InsertMode addv)

Not Collective

### Input Parameters

| mat | - the matrix
| v | - a logically two-dimensional array of values
| m, idxm | - the number of rows and their global indices
| n, idxn | - the number of columns and their global indices
| addv | - either ADD_VALUES or INSERT_VALUES, where ADD_VALUES adds values to any existing entries, and INSERT_VALUES replaces existing entries with new values

### Notes

By default the values, v, are row-oriented and unsorted. See MatSetOption() for other options.

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

MatSetValues() uses 0-based row and column numbers in Fortran as well as in C.

Negative indices may be passed in idxm and idxn, these rows and columns are simply ignored. This allows easily inserting element stiffness matrices with homogeneous Dirchlet boundary conditions that you don't want represented in the matrix.

### Efficiency Alert

The routine MatSetValuesBlocked() may offer much better efficiency for users of block sparse formats (MATSEQBAIJ and MATMPIBAIJ).

### See Also

MatSetOption(), MatAssemblyBegin(), MatAssemblyEnd(), MatSetValuesBlocked(), MatSetValuesLocal()

Level:beginner
Location: src/mat/interface/matrix.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/mat/examples/tutorials/ex2.c.html
src/ksp/pc/examples/tutorials/ex1.c.html
src/ksp/pc/examples/tutorials/ex2.c.html
src/ksp/examples/tutorials/ex1.c.html
src/ksp/examples/tutorials/ex2.c.html
src/ksp/examples/tutorials/ex3.c.html
src/ksp/examples/tutorials/ex4.c.html
src/ksp/examples/tutorials/ex5.c.html
src/ksp/examples/tutorials/ex7.c.html
src/ksp/examples/tutorials/ex8.c.html
src/ksp/examples/tutorials/ex9.c.html