adding better support for petsc4py in core PETSc

Lisandro Dalcin dalcinl at
Fri May 30 10:55:15 CDT 2008

I want to ask all you for adding better support for petsc4py in core PETSc.

All what I need to to add to opaque pointers in the base PetscObject
structure, like this

void *pycontext
PetscErrorcode  (*pydestroy)(void*)

As you see, this will not make core PETSc depend on Python in any way.
Additionally, the extra memory overhead is small, just to pointers..

My intention is to put a Python dictionary in the pycontext pointer,
and call pydestroy function pointer (I'll set if when needed) at the
time PetscHeaderDestroy is called.

Such a feature is currently being emulated with PetscContainer and
PetscObjectCompose, but I would really like to cleanup this hackery
and implement things the right way.

I've started to migrate my SWIG-based wrappers to use Cython. This is
preliminar and not yet ready for public consumption, but at firts I
anticipate this approach if far easier to understand, extend, and
maintain than the previous one. In the near future, making petsc4py
interoperate with C/C++/Fortran user code will be possible and easy.

For example, I saw the new Picard implementation in SNES. Such a
feature could be implemented with a few lines of pure Python code, no
point to have to write a full SNES type implementation (unless it is
really needed). Just write in Python a custom nonlinear solver, and
now run your C/C++/Fortran code with an special option in the command
line, and PETSc picks-up and used the Python code implementing your

Lisandro Dalcín
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594

More information about the petsc-dev mailing list