[petsc-dev] be careful comparing two PETSc objects by pointer

Barry Smith bsmith at mcs.anl.gov
Fri Apr 14 15:20:10 CDT 2017


  PETSc developers,

   Never "save" a vector (without increasing its reference count) (or any object) and later check if another vector is the same object by comparing the pointers. It could be the original vector was destroy and later a new one was created that uses the same memory so the comparison says equal when they were not. 

   Instead save the PetscObjectGetId() and compare the Ids; the Ids for objects are always unique (even if the object was destroyed).

   I found a nasty use of this in TS (which I may have written) which took Satish and I a while to debug.


   Barry




More information about the petsc-dev mailing list