# MatSetOption
Sets a parameter option for a matrix. Some options may be specific to certain storage formats.  Some options determine how values will be inserted (or added). Sorted, row-oriented input will generally assemble the fastest. The default is row-oriented. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatSetOption(Mat mat, MatOption op, PetscBool flg)
```
Logically Collective on mat for certain operations, such as `MAT_SPD`, not collective for `MAT_ROW_ORIENTED`, see `MatOption`


## Input Parameters

- ***mat -*** the matrix
- ***option -*** the option, one of those listed below (and possibly others),
- ***flg -*** turn the option on (`PETSC_TRUE`) or off (`PETSC_FALSE`)



## Options Describing Matrix Structure

- ***`MAT_SPD` -*** symmetric positive definite
- ***`MAT_SYMMETRIC` -*** symmetric in terms of both structure and value
- ***`MAT_HERMITIAN` -*** transpose is the complex conjugation
- ***`MAT_STRUCTURALLY_SYMMETRIC` -*** symmetric nonzero structure
- ***`MAT_SYMMETRY_ETERNAL` -*** indicates the symmetry (or Hermitian structure) or its absence will persist through any changes to the matrix
- ***`MAT_STRUCTURAL_SYMMETRY_ETERNAL` -*** indicates the structural symmetry or its absence will persist through any changes to the matrix
- ***`MAT_SPD_ETERNAL` -*** indicates the value of `MAT_SPD` (true or false) will persist through any changes to the matrix


These are not really options of the matrix, they are knowledge about the structure of the matrix that users may provide so that they
do not need to be computed (usually at a high cost)


## Options For Use with `MatSetValues()`
Insert a logically dense subblock, which can be

- ***`MAT_ROW_ORIENTED` -*** row-oriented (default)


Note these options reflect the data you pass in with `MatSetValues()`; it has
nothing to do with how the data is stored internally in the matrix
data structure.

When (re)assembling a matrix, we can restrict the input for
efficiency/debugging purposes.  These options include

- ***`MAT_NEW_NONZERO_LOCATIONS` -*** additional insertions will be allowed if they generate a new nonzero (slow)
- ***`MAT_FORCE_DIAGONAL_ENTRIES` -*** forces diagonal entries to be allocated
- ***`MAT_IGNORE_OFF_PROC_ENTRIES` -*** drops off-processor entries
- ***`MAT_NEW_NONZERO_LOCATION_ERR` -*** generates an error for new matrix entry
- ***`MAT_USE_HASH_TABLE` -*** uses a hash table to speed up matrix assembly
- ***`MAT_NO_OFF_PROC_ENTRIES` -*** you know each process will only set values for its own rows, will generate an error if
any process sets values for another process. This avoids all reductions in the MatAssembly routines and thus improves
performance for very large process counts.
- ***`MAT_SUBSET_OFF_PROC_ENTRIES` -*** you know that the first assembly after setting this flag will set a superset
of the off-process entries required for all subsequent assemblies. This avoids a rendezvous step in the MatAssembly
functions, instead sending only neighbor messages.



## Notes
Except for `MAT_UNUSED_NONZERO_LOCATION_ERR` and  `MAT_ROW_ORIENTED` all processes that share the matrix must pass the same value in flg!

Some options are relevant only for particular matrix types and
are thus ignored by others.  Other options are not supported by
certain matrix types and will generate an error message if set.

If using a Fortran 77 module to compute a matrix, one may need to
use the column-oriented option (or convert to the row-oriented
format).

`MAT_NEW_NONZERO_LOCATIONS` set to `PETSC_FALSE` indicates that any add or insertion
that would generate a new entry in the nonzero structure is instead
ignored.  Thus, if memory has not alredy been allocated for this particular
data, then the insertion is ignored. For dense matrices, in which
the entire array is allocated, no entries are ever ignored.
Set after the first `MatAssemblyEnd()`. If this option is set then the MatAssemblyBegin/End() processes has one less global reduction

`MAT_NEW_NONZERO_LOCATION_ERR` set to PETSC_TRUE indicates that any add or insertion
that would generate a new entry in the nonzero structure instead produces
an error. (Currently supported for `MATAIJ` and `MATBAIJ` formats only.) If this option is set then the `MatAssemblyBegin()`/`MatAssemblyEnd()` processes has one less global reduction

`MAT_NEW_NONZERO_ALLOCATION_ERR` set to `PETSC_TRUE` indicates that any add or insertion
that would generate a new entry that has not been preallocated will
instead produce an error. (Currently supported for `MATAIJ` and `MATBAIJ` formats
only.) This is a useful flag when debugging matrix memory preallocation.
If this option is set then the `MatAssemblyBegin()`/`MatAssemblyEnd()` processes has one less global reduction

`MAT_IGNORE_OFF_PROC_ENTRIES` set to `PETSC_TRUE` indicates entries destined for
other processors should be dropped, rather than stashed.
This is useful if you know that the "owning" processor is also
always generating the correct matrix entries, so that PETSc need
not transfer duplicate entries generated on another processor.

`MAT_USE_HASH_TABLE` indicates that a hash table be used to improve the
searches during matrix assembly. When this flag is set, the hash table
is created during the first matrix assembly. This hash table is
used the next time through, during `MatSetVaules()`/`MatSetVaulesBlocked()`
to improve the searching of indices. `MAT_NEW_NONZERO_LOCATIONS` flag
should be used with `MAT_USE_HASH_TABLE` flag. This option is currently
supported by` MATMPIBAIJ` format only.

`MAT_KEEP_NONZERO_PATTERN` indicates when `MatZeroRows()` is called the zeroed entries
are kept in the nonzero structure

`MAT_IGNORE_ZERO_ENTRIES` - for `MATAIJ` and `MATIS` matrices this will stop zero values from creating
a zero location in the matrix

`MAT_USE_INODES` - indicates using inode version of the code - works with `MATAIJ` matrix types

`MAT_NO_OFF_PROC_ZERO_ROWS` - you know each process will only zero its own rows. This avoids all reductions in the
zero row routines and thus improves performance for very large process counts.

`MAT_IGNORE_LOWER_TRIANGULAR` - For `MATSBAIJ` matrices will ignore any insertions you make in the lower triangular
part of the matrix (since they should match the upper triangular part).

`MAT_SORTED_FULL` - each process provides exactly its local rows; all column indices for a given row are passed in a
single call to `MatSetValues()`, preallocation is perfect, row oriented, `INSERT_VALUES` is used. Common
with finite difference schemes with non-periodic boundary conditions.


## Developer Note
`MAT_SYMMETRY_ETERNAL`, `MAT_STRUCTURAL_SYMMETRY_ETERNAL`, and `MAT_SPD_ETERNAL` are used by `MatAssemblyEnd()` and in other
places where otherwise the value of `MAT_SYMMETRIC`, `MAT_STRUCTURAL_SYMMETRIC` or `MAT_SPD` would need to be changed back
to `PETSC_BOOL3_UNKNOWN` because the matrix values had changed so the code cannot be certain that the related property had
not changed.




## See Also
 `MatOption`, `Mat`, `MatGetOption()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/interface/matrix.c.html#MatSetOption">src/mat/interface/matrix.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex12.c.html">src/mat/tutorials/ex12.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex16.c.html">src/mat/tutorials/ex16.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex4.c.html">src/mat/tutorials/ex4.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex4f.F90.html">src/mat/tutorials/ex4f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex5cu.cu.html">src/mat/tutorials/ex5cu.cu.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex5k.kokkos.cxx.html">src/mat/tutorials/ex5k.kokkos.cxx.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/tutorials/ex3.c.html">src/ksp/pc/tutorials/ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex18.c.html">src/ksp/ksp/tutorials/ex18.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex2.c.html">src/ksp/ksp/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex21.c.html">src/ksp/ksp/tutorials/ex21.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex4.c.html">src/ksp/ksp/tutorials/ex4.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/adj/mpi/mpiadj.c.html#MatSetOption_MPIAdj">MatSetOption_MPIAdj in src/mat/impls/adj/mpi/mpiadj.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatSetOption_MPIAIJ">MatSetOption_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/aij.c.html#MatSetOption_SeqAIJ">MatSetOption_SeqAIJ in src/mat/impls/aij/seq/aij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx.html#MatSetOption_SeqAIJKokkos">MatSetOption_SeqAIJKokkos in src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu.html#MatSetOption_SeqAIJCUSPARSE">MatSetOption_SeqAIJCUSPARSE in src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c.html#MatSetOption_SeqAIJHIPSPARSE">MatSetOption_SeqAIJHIPSPARSE in src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/mpi/mpibaij.c.html#MatSetOption_MPIBAIJ">MatSetOption_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/baij/seq/baij.c.html#MatSetOption_SeqBAIJ">MatSetOption_SeqBAIJ in src/mat/impls/baij/seq/baij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/blockmat/seq/blockmat.c.html#MatSetOption_BlockMat">MatSetOption_BlockMat in src/mat/impls/blockmat/seq/blockmat.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/mpi/mpidense.c.html#MatSetOption_MPIDense">MatSetOption_MPIDense in src/mat/impls/dense/mpi/mpidense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/dense/seq/dense.c.html#MatSetOption_SeqDense">MatSetOption_SeqDense in src/mat/impls/dense/seq/dense.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/elemental/matelem.cxx.html#MatSetOption_Elemental">MatSetOption_Elemental in src/mat/impls/elemental/matelem.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/hypre/mhypre.c.html#MatSetOption_HYPRE">MatSetOption_HYPRE in src/mat/impls/hypre/mhypre.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/is/matis.c.html#MatSetOption_IS">MatSetOption_IS in src/mat/impls/is/matis.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/preallocator/matpreallocator.c.html#MatSetOption_Preallocator">MatSetOption_Preallocator in src/mat/impls/preallocator/matpreallocator.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/mpi/mpisbaij.c.html#MatSetOption_MPISBAIJ">MatSetOption_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sbaij/seq/sbaij.c.html#MatSetOption_SeqSBAIJ">MatSetOption_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/scalapack/matscalapack.c.html#MatSetOption_ScaLAPACK">MatSetOption_ScaLAPACK in src/mat/impls/scalapack/matscalapack.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/mpi/mpisell.c.html#MatSetOption_MPISELL">MatSetOption_MPISELL in src/mat/impls/sell/mpi/mpisell.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/seq/sell.c.html#MatSetOption_SeqSELL">MatSetOption_SeqSELL in src/mat/impls/sell/seq/sell.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/interface/matrix.c)


[Index of all Mat routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
