:orphan:
# MatSetDM
Sets the `DM` defining the data layout of the matrix
## Synopsis
```
#include "petscdm.h"
#include "petscdmlabel.h"
#include "petscds.h"
PetscErrorCode MatSetDM(Mat A, DM dm)
```
Not Collective
## Input Parameters
- ***A -*** The `Mat`
- ***dm -*** The `DM`
## Note
This is rarely used in practice, rather `DMCreateMatrix()` is used to create a matrix associated with a particular `DM`
## Developer Note
Since the `Mat` class doesn't know about the `DM` class the `DM` object is associated with
the `Mat` through a `PetscObjectCompose()` operation
## See Also
[](ch_dmbase), `DM`, `MatGetDM()`, `DMCreateMatrix()`, `DMSetMatType()`
## Level
developer
## Location
src/dm/interface/dm.c
## Examples
src/ksp/ksp/tutorials/ex29.c
src/ksp/ksp/tutorials/ex34.c
src/snes/tutorials/ex22.c
src/snes/tutorials/ex35.c
---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/dm/interface/dm.c)
[Index of all DM routines](index.md)
[Table of Contents for all manual pages](/manualpages/index.md)
[Index of all manual pages](/manualpages/singleindex.md)