[petsc-dev] Remove calls to XXXReset() in XXXDestroy()

Lisandro Dalcin dalcinl at gmail.com
Fri May 13 07:01:46 CDT 2011


On 13 May 2011 01:51, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
> On May 12, 2011, at 4:48 PM, Lisandro Dalcin wrote:
>
>> I had the same issue with MatPreallocated() hack at MatDestroy(), that
>> I could fortunately fix in a recent commit.
>
>   So this has nothing to do with XXXReset() in particular? It only has to do with calling a method on an object inside the object destroy?

Yes, that's precisely the issue.

>
> And is it for any object destroy, or only an object whose subclass is implemented in python?
>

I would say that it is a Python issue. In general terms, running
Python code when an object is about to be destroyed is problematic. Do
you know that if a Python class implements "def __del__() " then
Python bans it from participating in garbage collection?.

However, this issue could also affect other languages (like C++)
wrapping a PETSc object.

>
>   Why is calling a method inside XXXDestroy() such a problem? It sure isn't a problem for the C level, what causes the problem for python?
>

It is a problem about reference count management. In C you'll never
have issues because you do not have a garbage collector in your back.
Also, C forces you to be more careful about object lifetime. Python is
so dynamic that it is easy to screw things up if the C library you are
wrapping do not help a little.

Finally, note that I think I got things working in petsc4py, so
changing PETSc is not strictly required.

However, there is still the point of why to mix Reset() with
Destroy(). They serve different purposes. This story is more or less
the MatPreallocated() thing, it should not be there at a Destroy()
call.

Barry, now I want to understand: Why did you coded XXXDestroy() to
call XXXReset()? Was that just to avoid code duplication? Or is it
there some other rationale?


-- 
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
3000 Santa Fe, Argentina
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169



More information about the petsc-dev mailing list