Skip to main content
`Ctrl`+`K`

# 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 of ‘y’. Likewise, the `n` used must match the local size of ‘x’.

If `m` and `n` are not `PETSC_DECIDE`, then the values determine the `PetscLayout` of the matrix and the ranges returned by `MatGetOwnershipRange()`, `MatGetOwnershipRanges()`, `MatGetOwnershipRangeColumn()`, and `MatGetOwnershipRangesColumn()`.

You cannot change the sizes once they have been set.

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

## See Also

Matrices, `Mat`, `MatGetSize()`, `PetscSplitOwnership()`, `MatGetOwnershipRange()`, `MatGetOwnershipRanges()`, `MatGetOwnershipRangeColumn()`, `MatGetOwnershipRangesColumn()`, `PetscLayout`, `VecSetSizes()`

## Level

beginner

## Location

src/mat/utils/gcreate.c

## Examples

src/ksp/ksp/tutorials/ex1.c
src/ksp/ksp/tutorials/ex15.c
src/ksp/ksp/tutorials/ex100.c
src/ksp/ksp/tutorials/ex18.c
src/ksp/ksp/tutorials/ex19.c
src/ksp/ksp/tutorials/ex12.c
src/ksp/ksp/tutorials/ex16.c
src/ksp/ksp/tutorials/ex23.c
src/ksp/ksp/tutorials/ex11.c
src/ksp/ksp/tutorials/ex3.c

Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages