Use VecGetArray() and then loop over the array entries performing whatever element operations you like.
For dense matrices use MatDenseGetArray() and loop over the entries. For sequential AIJ matrices uses MatSeqAIJGetArray() For MPIAIJ use MatMPIAIJGetSeqAIJ() then use MatSeqAIJGetArray on each of the two matrices. Barry > On Jan 5, 2021, at 9:24 AM, Roland Richter <[email protected]> wrote: > > Hei, > > is there a function to square/cube etc. each element of a matrix or > vector in PETSc? It is rather useful for things like intensity > calculations (I = |E|^2), and should work also for distributed matrices. > > Thanks! > > Regards, > > Roland Richter >
