:orphan:
# MatCreate
Creates a matrix where the type is determined from either a call to `MatSetType()` or from the options database with a call to `MatSetFromOptions()`. The default matrix type is `MATAIJ`, using the routines `MatCreateSeqAIJ()` or `MatCreateAIJ()` if you do not set a type in the options database. If you never call `MatSetType()` or `MatSetFromOptions()` it will generate an error when you try to use the matrix.
## Synopsis
```
#include "petscmat.h"
PetscErrorCode MatCreate(MPI_Comm comm, Mat *A)
```
Collective
## Input Parameter
- ***comm -*** MPI communicator
## Output 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`, uses `MatCreateSeqDense()`
- ***-mat_type mpidense -*** `MATMPIDENSE` type, uses `MatCreateDense()`
- ***-mat_type seqbaij -*** `MATSEQBAIJ` type, uses `MatCreateSeqBAIJ()`
- ***-mat_type mpibaij -*** `MATMPIBAIJ` type, uses `MatCreateBAIJ()`
See the manpages for particular formats (e.g., `MATSEQAIJ`)
for additional format-specific options.
## See Also
[](ch_matrices), `Mat`, `MatCreateSeqAIJ()`, `MatCreateAIJ()`,
`MatCreateSeqDense()`, `MatCreateDense()`,
`MatCreateSeqBAIJ()`, `MatCreateBAIJ()`,
`MatCreateSeqSBAIJ()`, `MatCreateSBAIJ()`,
`MatConvert()`
## Level
beginner
## Location
src/mat/utils/gcreate.c
## Examples
src/ksp/ksp/tutorials/bench_kspsolve.c
src/ksp/ksp/tutorials/ex1.c
src/ksp/ksp/tutorials/ex10.c
src/ksp/ksp/tutorials/ex100.c
src/ksp/ksp/tutorials/ex100f.F90
src/ksp/ksp/tutorials/ex11.c
src/ksp/ksp/tutorials/ex11f.F90
src/ksp/ksp/tutorials/ex12.c
src/ksp/ksp/tutorials/ex15.c
src/ksp/ksp/tutorials/ex15f.F90
src/ksp/ksp/tutorials/ex16.c
## Implementations
MatCreate_HYPREStruct in src/dm/impls/da/hypre/mhyp.c
MatCreate_HYPRESStruct in src/dm/impls/da/hypre/mhyp.c
MatCreate_MPIAdj in src/mat/impls/adj/mpi/mpiadj.c
MatCreate_MPIAIJMKL in src/mat/impls/aij/mpi/aijmkl/mpiaijmkl.c
MatCreate_MPIAIJPERM in src/mat/impls/aij/mpi/aijperm/mpiaijperm.c
MatCreate_MPIAIJSELL in src/mat/impls/aij/mpi/aijsell/mpiaijsell.c
MatCreate_MPIAIJCRL in src/mat/impls/aij/mpi/crl/mcrl.c
MatCreate_MPIAIJKokkos in src/mat/impls/aij/mpi/kokkos/mpiaijkok.kokkos.cxx
MatCreate_MPIAIJ in src/mat/impls/aij/mpi/mpiaij.c
MatCreate_MPIAIJCUSPARSE in src/mat/impls/aij/mpi/mpicusparse/mpiaijcusparse.cu
MatCreate_MPIAIJHIPSPARSE in src/mat/impls/aij/mpi/mpihipsparse/mpiaijhipsparse.hip.c
MatCreate_MPIAIJViennaCL in src/mat/impls/aij/mpi/mpiviennacl/mpiaijviennacl.cxx
MatCreate_SeqAIJ in src/mat/impls/aij/seq/aij.c
MatCreate_SeqAIJMKL in src/mat/impls/aij/seq/aijmkl/aijmkl.c
MatCreate_SeqAIJPERM in src/mat/impls/aij/seq/aijperm/aijperm.c
MatCreate_SeqAIJSELL in src/mat/impls/aij/seq/aijsell/aijsell.c
MatCreate_SeqAIJCRL in src/mat/impls/aij/seq/crl/crl.c
MatCreate_SeqAIJKokkos in src/mat/impls/aij/seq/kokkos/aijkok.kokkos.cxx
MatCreate_SeqAIJCUSPARSE in src/mat/impls/aij/seq/seqcusparse/aijcusparse.cu
MatCreate_SeqAIJHIPSPARSE in src/mat/impls/aij/seq/seqhipsparse/aijhipsparse.hip.c
MatCreate_SeqAIJViennaCL in src/mat/impls/aij/seq/seqviennacl/aijviennacl.cxx
MatCreate_MPIBAIJMKL in src/mat/impls/baij/mpi/baijmkl/mpibaijmkl.c
MatCreate_MPIBAIJ in src/mat/impls/baij/mpi/mpibaij.c
MatCreate_SeqBAIJ in src/mat/impls/baij/seq/baij.c
MatCreate_SeqBAIJMKL in src/mat/impls/baij/seq/baijmkl/baijmkl.c
MatCreate_BlockMat in src/mat/impls/blockmat/seq/blockmat.c
MatCreate_ConstantDiagonal in src/mat/impls/cdiagonal/cdiagonal.c
MatCreate_Composite in src/mat/impls/composite/mcomposite.c
MatCreate_MPIDenseCUDA in src/mat/impls/dense/mpi/cupm/cuda/matmpidensecuda.cu
MatCreate_MPIDenseHIP in src/mat/impls/dense/mpi/cupm/hip/matmpidensehip.hip.c
MatCreate_MPIDense in src/mat/impls/dense/mpi/mpidense.c
MatCreate_SeqDenseCUDA in src/mat/impls/dense/seq/cupm/cuda/matseqdensecuda.cu
MatCreate_SeqDenseHIP in src/mat/impls/dense/seq/cupm/hip/matseqdensehip.hip.c
MatCreate_SeqDense in src/mat/impls/dense/seq/dense.c
MatCreate_Dummy in src/mat/impls/dummy/matdummy.c
MatCreate_Elemental in src/mat/impls/elemental/matelem.cxx
MatCreate_FFTW in src/mat/impls/fft/fftw/fftw.c
MatCreate_H2OPUS in src/mat/impls/h2opus/cuda/math2opus.cu
MatCreate_Htool in src/mat/impls/htool/htool.cxx
MatCreate_HYPRE in src/mat/impls/hypre/mhypre.c
MatCreate_IS in src/mat/impls/is/matis.c
MatCreate_KAIJ in src/mat/impls/kaij/kaij.c
MatCreate_MAIJ in src/mat/impls/maij/maij.c
MatCreate_MFFD in src/mat/impls/mffd/mffd.c
MatCreate_Nest in src/mat/impls/nest/matnest.c
MatCreate_Preallocator in src/mat/impls/preallocator/matpreallocator.c
MatCreate_MPISBAIJ in src/mat/impls/sbaij/mpi/mpisbaij.c
MatCreate_SeqSBAIJ in src/mat/impls/sbaij/seq/sbaij.c
MatCreate_ScaLAPACK in src/mat/impls/scalapack/matscalapack.c
MatCreate_Scatter in src/mat/impls/scatter/mscatter.c
MatCreate_MPISELL in src/mat/impls/sell/mpi/mpisell.c
MatCreate_SeqSELL in src/mat/impls/sell/seq/sell.c
MatCreate_Shell in src/mat/impls/shell/shell.c
---
[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](/manualpages/index.md)
[Index of all manual pages](/manualpages/singleindex.md)