# MatReorderForNonzeroDiagonal
Changes matrix ordering to remove zeros from diagonal. This may help in the `PCLU` factorization to prevent a zero pivot. 
## Synopsis
```
#include "petscmat.h"  
PetscErrorCode MatReorderForNonzeroDiagonal(Mat mat, PetscReal abstol, IS ris, IS cis)
```
Collective


## Input Parameters

- ***mat  -*** matrix to reorder
- ***rmap,cmap -*** row and column permutations.  Usually obtained from
`MatGetOrdering()`.





## Notes
This is not intended as a replacement for pivoting for matrices that
have ``bad'' structure. It is only a stop-gap measure. Should be called
after a call to `MatGetOrdering()`, this routine changes the column
ordering defined in cis.

Only works for `MATSEQAIJ` matrices


## Options Database Keys (When using `KSP`)

- ***-pc_factor_nonzeros_along_diagonal -*** Reorder to remove zeros from diagonal



## Algorithm Notes
Column pivoting is used.

1) Choice of column is made by looking at the
non-zero elements in the troublesome row for columns that are not yet
included (moving from left to right).

2) If (1) fails we check all the columns to the left of the current row
and see if one of them has could be swapped. It can be swapped if
its corresponding row has a non-zero in the column it is being
swapped with; to make sure the previous nonzero diagonal remains
nonzero


## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/utils/zerodiag.c.html#MatReorderForNonzeroDiagonal">src/mat/utils/zerodiag.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/utils/zerodiag.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)  
