Skip to main content
`Ctrl`+`K`

# MatColoringCreate

Creates a matrix coloring context.

## Synopsis

    #include "petscmat.h"
    PetscErrorCode MatColoringCreate(Mat m, MatColoring *mcptr)

Collective

## Input Parameter

- m - MPI communicator

## Output Parameter

- mcptr - the new `MatColoring` context

## Options Database Keys

- -mat_coloring_type - the type of coloring algorithm used. See `MatColoringType`.

- -mat_coloring_maxcolors - the maximum number of relevant colors, all nodes not in a color are in maxcolors+1

- -mat_coloring_distance - compute a distance 1,2,… coloring.

- -mat_coloring_view - print information about the coloring and the produced index sets

- -mat_coloring_test - debugging option that prints all coloring incompatibilities

- -mat_is_coloring_test - debugging option that throws an error if MatColoringApply() generates an incorrect iscoloring

## Notes

A distance one coloring is useful, for example, multi-color SOR.

A distance two coloring is for the finite difference computation of Jacobians (see `MatFDColoringCreate()`).

Coloring of matrices can be computed directly from the sparse matrix nonzero structure via the `MatColoring` object or from the mesh from which the matrix comes from with `DMCreateColoring()`. In general using the mesh produces a more optimal coloring (fewer colors).

Some coloring types only support distance two colorings

## See Also

`MatColoringSetFromOptions()`, `MatColoring`, `MatColoringApply()`, `MatFDColoringCreate()`, `DMCreateColoring()`, `MatColoringType`

## Level

beginner

## Location

src/mat/graphops/color/interface/matcoloring.c

## Examples

src/mat/tutorials/ex16.c

## Implementations

MatColoringCreate_Greedy() in src/mat/graphops/color/impls/greedy/greedy.c
MatColoringCreate_JP() in src/mat/graphops/color/impls/jp/jp.c
MatColoringCreate_SL() in src/mat/graphops/color/impls/minpack/color.c
MatColoringCreate_LF() in src/mat/graphops/color/impls/minpack/color.c
MatColoringCreate_ID() in src/mat/graphops/color/impls/minpack/color.c
MatColoringCreate_Natural() in src/mat/graphops/color/impls/natural/natural.c
MatColoringCreate_Power() in src/mat/graphops/color/impls/power/power.c

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