The manpage http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetDiagonalBlock.html indicates the reference counter on the returned matrix (a) isn't incremented.
This statement would imply that in the absence of calling PetscObjectReference() yourself, you should not call MatDestroy() on the matrix returned. If you do call MatDestroy(), a double free will occur when you call MatDestroy() on the parent matrix from which you pulled the block matrix out of. Cheers, Dave On 6 January 2016 at 00:14, Bhalla, Amneet Pal S <amne...@live.unc.edu> wrote: > Hi Folks, > > Is it safe to call MatDestroy on the sequential matrix returned by > MatGetDiagonalBlock() after it’s no longer used? > > > Thanks, > > — Amneet > ===================================================== > Amneet Bhalla > Postdoctoral Research Associate > Department of Mathematics and McAllister Heart Institute > University of North Carolina at Chapel Hill > Email: amn...@unc.edu > Web: https://abhalla.web.unc.edu > ===================================================== > >