[petsc-dev] Why do we use void* instead of PetscObject in PETSc?

Smith, Barry F. bsmith at mcs.anl.gov
Sun Mar 3 21:26:47 CST 2019


   There is a lot of merit for this alternative approach. 

   This suggestion is also closely related to the (I think it's Toby's) proposal to replace the (function), ctx pairs  that manage call backs in PETSc with objects. 

    There will be a bit of an issue with dealing with the Fortran code but presumably it will be manageable.

    Barry

    So my question is, what would be the major win to devoting the resources to make this change now versus putting it off indefinitely?

  

> On Mar 2, 2019, at 10:19 AM, Dave May via petsc-dev <petsc-dev at mcs.anl.gov> wrote:
> 
> I think there would be a lot of merit (in the long run) if user contexts, such as given to KSPSetComputeOperators(), SNESSetJacobian() etc were changed to be of type PetscObject rather than void*.
> 
> Some obvious benefits would be:
> [1] Type checking!
> [2] User contexts could be readily shared using PetscObjects reference counter (PetscObjectReferenece()).
> [3] User contexts would have a communicator.
> [4] User contexts could have textual names associated with them (PetscObjectSetName()).
> [5] Internal to PETSc (e.g. within KSPComputeOperators_SNES) the header of the context could be checked to ensure the type of the PetscObject is valid (SNES in this example).
> 
> If this change was adopted, the user could readily change their code to use a PetscContainer. Such a change avoids the user having to recreate their own object model / class to deal with simple issues associated with sharing a context, or having to manage communicators within their own contexts.
> 
> I see the point that the context is "the users problem". Many PETSc examples simply use a pointer to typedef'd struct as the context. Users tend to copy examples, and really, a simple struct with a bunch of parameters is not a good object model to be followed. Would it be so horrible to require users to put "their problem" (e.g. context) inside a PetscObject?
> 
> Besides the huge volume of work required to change internal PETSc code and more over, the code of all users, are there genuinely compelling reasons to keep using void* everywhere? I cannot think of one, but I would like to hear others thoughts on this. (Maybe there are concerns with Fortran compatibility?). 
> 
> 
> Thanks
> Dave
> 
> 
> 



More information about the petsc-dev mailing list