# MatSetSizes
Sets the local and global sizes, and checks to determine compatibility 
## Synopsis
```
#include "petscmat.h"  
PetscErrorCode MatSetSizes(Mat A, PetscInt m, PetscInt n, PetscInt M, PetscInt N)
```
Collective


## Input Parameters

- ***A -*** the matrix
- ***m -*** number of local rows (or `PETSC_DECIDE`)
- ***n -*** number of local columns (or `PETSC_DECIDE`)
- ***M -*** number of global rows (or `PETSC_DETERMINE`)
- ***N -*** number of global columns (or `PETSC_DETERMINE`)



## Notes
m (n) and M (N) cannot be both `PETSC_DECIDE`
If one processor calls this with M (N) of `PETSC_DECIDE` then all processors must, otherwise the program will hang.

If `PETSC_DECIDE` is not used for the arguments 'm' and 'n', then the
user must ensure that they are chosen to be compatible with the
vectors. To do this, one first considers the matrix-vector product
'y = A x'. The 'm' that is used in the above routine must match the
local size used in the vector creation routine VecCreateMPI() for 'y'.
Likewise, the 'n' used must match that used as the local size in
`VecCreateMPI()` for 'x'.

You cannot change the sizes once they have been set.

The sizes must be set before `MatSetUp()` or MatXXXSetPreallocation() is called.




## See Also
 `MatGetSize()`, `PetscSplitOwnership()`

## Level
beginner

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

## Examples
<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/ex18.c.html">src/mat/tutorials/ex18.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/tutorials/ex2.c.html">src/mat/tutorials/ex2.c.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/mat/tutorials/ex8.c.html">src/mat/tutorials/ex8.c.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/bench_pcsetup.c.html">src/ksp/ksp/tutorials/bench_pcsetup.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex1.c.html">src/ksp/ksp/tutorials/ex1.c.html</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)  
