[petsc-users] Extending petsc4py

Ingo Gaertner ingogaertner.tus at gmail.com
Wed Jul 11 14:48:08 CDT 2018


I am sorry. I meant to ask about petsc4py only, so please replace every
mpi4py in my question with petsc4py.
The "demo/wrap-swig" has solved my problems.

Thanks
Ingo

2018-07-11 11:26 GMT+02:00 Lisandro Dalcin <dalcinl at gmail.com>:

>
>
> On Tue, 10 Jul 2018 at 20:17, Ingo Gaertner <ingogaertner.tus at gmail.com>
> wrote:
>
>> Hello,
>> can I find somewhere an example how to wrap my own PETSc-based code so
>> that it can be used together with petsc4py?
>>
>> Let's assume I have a C function, which I want to access from python:
>> Vec createMyVec();
>>
>> I have written a SWIG interface file to generate a python wrapper for
>> this function. The wrapper works, but I cannot use the return value as
>> input for mpi4py routines that expect a Vec, because mpi4py's Vec type is
>> different from the SWIG generated Vec type in my python wrapper. Any idea,
>> how I can create mpi4py-compatible types?
>>
>> If the mpi4py wrapping technique is described somewhere, this may help as
>> well, although some working example would be perfect.
>>
>> As a final remark, I'd like to keep my project decoupled from mpi4py.
>> Therefore, including my extensions in the build process of mpi4py is not
>> quite what I am looking for, although I could live with this as a
>> workaround if no other solution is possible.
>> (I am using petsc-3.9.1 built from source and mpi4py installed using pip
>> on Ubuntu 18.04.)
>>
>>
> Sorry, but I'm quite confused. Why are you talking about mpi4py? There is
> no "Vec" in mpi4py. The only type intersection between petsc4py and mpi4py
> is "Comm" for MPI communicators, in that case you should use the following
> to make the conversions:
>
> mpi4py_comm = petsc4py_comm.tompi4py() # mpi4py <-- petsc4py
> petsc4py_comm = PETSc.Comm(mpi4py_comm) # petsc4py <-- mpi4py
>
> About SWIG, are you using typemaps written by yourself, or the typemaps
> provided by petsc4py? Have you looked at "demo/wrap-swig" in petsc4py
> sources?
>
> --
> Lisandro Dalcin
> ============
> Research Scientist
> Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
> Extreme Computing Research Center (ECRC)
> King Abdullah University of Science and Technology (KAUST)
> http://ecrc.kaust.edu.sa/
>
> 4700 King Abdullah University of Science and Technology
> al-Khawarizmi Bldg (Bldg 1), Office # 0109
> Thuwal 23955-6900, Kingdom of Saudi Arabia
> http://www.kaust.edu.sa
>
> Office Phone: +966 12 808-0459
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20180711/9dc43280/attachment.html>


More information about the petsc-users mailing list