# Get a matrix with absolute values in PETSc [closed]

Is there any function to create or change a matrix, to have $A_{ij} = \text{abs}(A_{ij})$ in PETSc? If possible it should work with MPIAIJ matrices, not only local.

From MatRealPart subroutine source code, the following excerpt is doing the job
(*mat->ops->realpart)(mat);

The list of supported and propagated operations on matrices is stored in include/petscmat.h in MatOperation typedef. Technically, you can code up your own operation and propagate it to the datatypes you require (maybe, even by using custom user matrix MatOperation and MatShellSetOperation). However, the question is if such a development is worth the required time and pain.