# MatGetTrace Gets the trace of a matrix. The sum of the diagonal entries. ## Synopsis ``` #include "petscmat.h" PetscErrorCode MatGetTrace(Mat mat, PetscScalar *trace) ``` Collective ## Input Parameters - ***mat -*** the matrix ## Output Parameter - ***trace -*** the sum of the diagonal entries ## See Also `Mat` ## Level advanced ## Location src/mat/interface/matrix.c --- [Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/interface/matrix.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)