[petsc-users] Calling Pytorch and Python within PETSc C/C++ code

Barry Smith bsmith at petsc.dev
Mon Jun 13 16:11:28 CDT 2022


  Note that your Python main ptsc4py program can call C/C++ code for some of its computations, so if you have a lot of C/C++ code you do not need to change it all to Python. It is also possible to call Petsc4py (and hence PyTorch) from a C/C++ main but a bit more cumbersome so not recommended. See src/ksp/ksp/tutorials/ex100.c and ex100.py for an example of a C/C++ main that uses petsc4py (in a limited way). 

> On Jun 13, 2022, at 4:42 PM, Zhang, Hong via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> No. It is not common to execute Python scripts or libraries from C/C++ code. If you are looking for ways to use PETSc and PyTorch together, it is best to build your application in Python so that you can use both petsc4py and PyTorch. See the following code for an example:
> https://github.com/caidao22/pnode <https://github.com/caidao22/pnode>
> 
> Hong (Mr.)
> 
>> On Jun 13, 2022, at 9:50 AM, Amneet Bhalla <mail2amneet at gmail.com <mailto:mail2amneet at gmail.com>> wrote:
>> 
>> 
>> Hi Guys,
>> 
>> Is there a PETSc interface to make calls to Python scripts or libraries (e.g., Pytorch) from a C/C++ code making use of PETSc? If so, are there some examples that I refer to?
>> 
>> Thanks, 
>> -- 
>> --Amneet 
>> 
>> 
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220613/4c2193a5/attachment-0001.html>


More information about the petsc-users mailing list