# KSPSetDiagonalScale
Tells `KSP` to symmetrically diagonally scale the system before solving. This actually CHANGES the matrix (and right hand side). 
## Synopsis
```
#include "petscksp.h" 
#include "petscmat.h" 
PetscErrorCode KSPSetDiagonalScale(KSP ksp, PetscBool scale)
```
Logically Collective on ksp


## Input Parameters

- ***ksp -*** the `KSP` context
- ***scale -*** `PETSC_TRUE` or `PETSC_FALSE`



## Options Database Key

- ***-ksp_diagonal_scale -*** 
- ***-ksp_diagonal_scale_fix -*** scale the matrix back AFTER the solve





## Notes
Scales the matrix by  D^(-1/2)  A  D^(-1/2)  [D^(1/2) x ] = D^(-1/2) b
where D_{ii} is 1/abs(A_{ii}) unless A_{ii} is zero and then it is 1.

BE CAREFUL with this routine: it actually scales the matrix and right
hand side that define the system. After the system is solved the matrix
and right hand side remain scaled unless you use `KSPSetDiagonalScaleFix()`

This should NOT be used within the `SNES` solves if you are using a line
search.

If you use this with the `PCType` `PCEISENSTAT` preconditioner than you can
use the `PCEisenstatSetNoDiagonalScaling()` option, or -pc_eisenstat_no_diagonal_scaling
to save some unneeded, redundant flops.


## See Also
 [](chapter_ksp), `KSPGetDiagonalScale()`, `KSPSetDiagonalScaleFix()`, `KSP`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/interface/itfunc.c.html#KSPSetDiagonalScale">src/ksp/ksp/interface/itfunc.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/ksp/ksp/interface/itfunc.c)


[Index of all KSP routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
