# MatSetFromOptions
Creates a matrix where the type is determined from the options database. Generates a parallel MPI matrix if the communicator has more than one processor.  The default matrix type is `MATAIJ`, using the routines `MatCreateSeqAIJ()` and `MatCreateAIJ()` if you do not select a type in the options database. 
## Synopsis
```
#include "petscmat.h"  
PetscErrorCode MatSetFromOptions(Mat B)
```
Collective on B


## Input Parameter

- ***A -*** the matrix



## Options Database Keys

- ***-mat_type seqaij   -*** `MATSEQAIJ` type, uses `MatCreateSeqAIJ()`
- ***-mat_type mpiaij   -*** `MATMPIAIJ` type, uses `MatCreateAIJ()`
- ***-mat_type seqdense -*** `MATSEQDENSE` type, uses `MatCreateSeqDense()`
- ***-mat_type mpidense -*** `MATMPIDENSE`, uses `MatCreateDense()`
- ***-mat_type seqbaij  -*** `MATSEQBAIJ`, uses `MatCreateSeqBAIJ()`
- ***-mat_type mpibaij  -*** `MATMPIBAIJ`, uses `MatCreateBAIJ()`



## Even More Options Database Keys
See the manpages for particular formats (e.g., `MatCreateSeqAIJ()`)
for additional format-specific options.




## See Also
 `MatCreateSeqAIJ(()`, `MatCreateAIJ()`,
`MatCreateSeqDense()`, `MatCreateDense()`,
`MatCreateSeqBAIJ()`, `MatCreateBAIJ()`,
`MatCreateSeqSBAIJ()`, `MatCreateSBAIJ()`,
`MatConvert()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/utils/gcreate.c.html#MatSetFromOptions">src/mat/utils/gcreate.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex10.c.html">src/mat/tutorials/ex10.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex15.c.html">src/mat/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex15f.F90.html">src/mat/tutorials/ex15f.F90.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/ex17.c.html">src/mat/tutorials/ex17.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex17f.F90.html">src/mat/tutorials/ex17f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex18.c.html">src/mat/tutorials/ex18.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>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpiaij.c.html#MatSetFromOptions_MPIAIJ">MatSetFromOptions_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu.html#MatSetFromOptions_MPIAIJCUSPARSE">MatSetFromOptions_MPIAIJCUSPARSE in src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mpihipsparse/mpiaijhipsparse.hip.c.html#MatSetFromOptions_MPIAIJHIPSPARSE">MatSetFromOptions_MPIAIJHIPSPARSE in src/mat/impls/aij/mpi/mpihipsparse/mpiaijhipsparse.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/mpi/mumps/mumps.c.html#MatSetFromOptions_MUMPS">MatSetFromOptions_MUMPS in src/mat/impls/aij/mpi/mumps/mumps.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu.html#MatSetFromOptions_SeqAIJCUSPARSE">MatSetFromOptions_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#MatSetFromOptions_SeqAIJHIPSPARSE">MatSetFromOptions_SeqAIJHIPSPARSE in src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/composite/mcomposite.c.html#MatSetFromOptions_Composite">MatSetFromOptions_Composite in src/mat/impls/composite/mcomposite.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/h2opus/cuda/math2opus.cu.html#MatSetFromOptions_H2OPUS">MatSetFromOptions_H2OPUS in src/mat/impls/h2opus/cuda/math2opus.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/htool/htool.cxx.html#MatSetFromOptions_Htool">MatSetFromOptions_Htool in src/mat/impls/htool/htool.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/is/matis.c.html#MatSetFromOptions_IS">MatSetFromOptions_IS in src/mat/impls/is/matis.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/mffd/mffd.c.html#MatSetFromOptions_MFFD">MatSetFromOptions_MFFD in src/mat/impls/mffd/mffd.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/impls/sell/mpi/mpisell.c.html#MatSetFromOptions_MPISELL">MatSetFromOptions_MPISELL in src/mat/impls/sell/mpi/mpisell.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/utils/gcreate.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)  
