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

Dave May dave.mayhem23 at gmail.com
Mon Mar 4 15:41:00 CST 2019


On Mon, 4 Mar 2019 at 21:30, Jed Brown <jed at jedbrown.org> wrote:

> Dave May via petsc-dev <petsc-dev at mcs.anl.gov> writes:
>
> > 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!
>
> How is passing a void* to PetscObject/PetscContainer different from
> passing it to SNES?


It's not.
The difference is that the void* business would be entirely pushed up into
the user code and moved out of PETSc.


> Also, would you have different types for every
> callback or would you reuse?


Reuse.


> If reusing, would the interface require
> casting the function pointers to void(*)(void) instead of what is
> currently type-safe for most function pointers?


No. I don't see that casting a function pointer would be required.
We would have

SNESSetJacobian(SNES snes,Mat Amat,Mat Pmat,PetscErrorCode
(*J)(SNES,Vec,Mat,Mat,PetscObject),PetscObject ctx)

Maybe I misunderstand your question.


> This feels like less
> rather than more type safety.
>
> Agree on other points.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20190304/eef54fc1/attachment.html>


More information about the petsc-dev mailing list