:orphan:
# DMCreateColoring
Gets coloring of a graph associated with the `DM`. Often the graph represents the operator matrix associated with the discretization of a PDE on the `DM`. 
## Synopsis
```
#include "petscdm.h"          
#include "petscdmlabel.h"     
#include "petscds.h"     
PetscErrorCode DMCreateColoring(DM dm, ISColoringType ctype, ISColoring *coloring)
```
Collective


## Input Parameters

- ***dm -*** the `DM` object
- ***ctype -*** `IS_COLORING_LOCAL` or `IS_COLORING_GLOBAL`



## Output Parameter

- ***coloring -*** the coloring





## Notes
Coloring of matrices can also be computed directly from the sparse matrix nonzero structure via the `MatColoring` object or from the mesh from which the
matrix comes from (what this function provides). In general using the mesh produces a more optimal coloring (fewer colors).

This produces a coloring with the distance of 2, see `MatSetColoringDistance()` which can be used for efficiently computing Jacobians with `MatFDColoringCreate()`
For `DMDA` in three dimensions with periodic boundary conditions the number of grid points in each dimension must be divisible by 2*stencil_width + 1,
otherwise an error will be generated.


## See Also
 [](ch_dmbase), `DM`, `ISColoring`, `DMDestroy()`, `DMView()`, `DMCreateGlobalVector()`, `DMCreateInterpolation()`, `DMCreateMatrix()`, `DMCreateMassMatrix()`, `DMSetMatType()`, `MatColoring`, `MatFDColoringCreate()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/interface/dm.c.html#DMCreateColoring">src/dm/interface/dm.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/tutorials/ex14.c.html">src/snes/tutorials/ex14.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/unconstrained/tutorials/minsurf2.c.html">src/tao/unconstrained/tutorials/minsurf2.c</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/composite/pack.c.html#DMCreateColoring_Composite">DMCreateColoring_Composite in src/dm/impls/composite/pack.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/da/fdda.c.html#DMCreateColoring_DA">DMCreateColoring_DA in src/dm/impls/da/fdda.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/redundant/dmredundant.c.html#DMCreateColoring_Redundant">DMCreateColoring_Redundant in src/dm/impls/redundant/dmredundant.c</A><BR>


---
[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)  
