petsc-3.7.1 2016-05-15
Report Typos and Errors

# 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"
    PetscErrorCode MatSetValues(Mat mat,PetscInt m,const PetscInt idxm[],PetscInt n,const PetscInt idxn[],const PetscScalar v[],InsertMode addv)

Not Collective Many br

### Input Parameters

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

### Notes

If you create the matrix yourself (that is not with a call to DMCreateMatrix()) then you MUST call MatXXXXSetPreallocation() or Many brMatSetUp() before using this routine Many br

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

Calls to MatSetValues() with the INSERT_VALUES and ADD_VALUES Many broptions cannot be mixed without intervening calls to the assembly Many brroutines. Many br

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

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

### Efficiency Alert

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

Many br

### See Also

MatSetOption(), MatAssemblyBegin(), MatAssemblyEnd(), MatSetValuesBlocked(), MatSetValuesLocal(),
InsertMode, INSERT_VALUES, ADD_VALUES Many br

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/mat/examples/tutorials/ex5.c.html
src/mat/examples/tutorials/ex8.c.html
src/mat/examples/tutorials/ex12.c.html
src/mat/examples/tutorials/ex15.c.html
src/mat/examples/tutorials/ex16.c.html
src/mat/examples/tutorials/ex17.c.html
src/ksp/pc/examples/tutorials/ex1.c.html
src/ksp/pc/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex1.c.html
src/ksp/ksp/examples/tutorials/ex2.c.html