# MatGetTrace
Gets the trace of a matrix. The sum of the diagonal entries. 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatGetTrace(Mat mat, PetscScalar *trace)
```
Collective on mat


## Input Parameters

- ***mat -*** the matrix



## Output Parameter

- ***trace -*** the sum of the diagonal entries





## See Also
 `Mat`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/interface/matrix.c.html#MatGetTrace">src/mat/interface/matrix.c</A>


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