[petsc-dev] PETSc future starting as a new design layer that runs on top of PETSc 3?

Lisandro Dalcin dalcinl at gmail.com
Sun Jul 31 08:17:27 CDT 2022


On Tue, 26 Jul 2022 at 17:35, Barry Smith <bsmith at petsc.dev> wrote:

>
>   Bindings for Fortran 20xx, Python 3, Julia? If the bindings are not,
> more or less, automatically generated, that would be problematic.
>
>
So far, PETSc exposes a C API. Of course it is object oriented in spirit,
but it is not object-oriented syntactically, and zero support function
overload, not default arguments or multiple return values, etc. because it
is rooted in C.

1) Then you want to automatically wrap Julia, which is also not
object-oriented, but sort of method-oriented, featuring multiple dispatch.
2) And also Python, which is syntactically object oriented, but has
no built-in/easy multiple dispatch or even function/method overload in
argument number and types.

And then you realize you cannot automatically generate an idiomatic, nice
looking, intuitive wrapper. You have to add "intellectual property" on top
of the base C API. Exactly as I had to do with mpi4py, although I had the
now long defunct C++ binding to provide inspiration.

IMHO, the only base language that is more or less amenable for automatic
Python binding generation is C++. Look at Qt, or perhaps better,
VTK/ParaView. They do a great job. Why? Because C++ is relatively easy to
map to Python (as long as your C++ API does not go crazy with templates).
We have pybind11, for example.

However, if the core of PETSc would become C++... would that still be the
case that generating Julia wrappers is easy? Maybe yes, if the base PETSc
C++ API constrains itself to follow a set or rules that would ease the map
of `object.method(args, ...)` to `method(object, args, ...)` and things
like that, but I'm not a Julia expert.

PS: Please don't take my words as advocacy for C++ (although it may be the
second worst choice after C). I'm just pointing out that mapping C ->
Python is not so easy to automate, unless you are OK with coding Python
with a wrapper that is C-like and thus very unpythonic.



-- 
Lisandro Dalcin
============
Senior Research Scientist
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20220731/90338656/attachment.html>


More information about the petsc-dev mailing list