[petsc-users] How to use f2py on a PETSc/SLEPc-based fortran code

Gaetan Kenway gaetank at gmail.com
Mon Mar 27 17:13:19 CDT 2017


Austin

Here is the full makefile for a code we use. The variables defined
externally in a separate config file are:
$(FF90)
$(FF90_FLAGS)
$(LIBDIR)
$(PETSC_LINKER_FLAGS)
$(LINKER_FLAGS)
$(CGNS_LINKER_FLAGS)

$(PYTHON)
$(PYTHON-CONIFG)
$(F2PY)
(These are usually use python, python-config and f2py. You can overwrite as
necessary)

$(CC)
$(CC_ALL_FLAGS)

This essentially just mimics what f2py does automatically but we found it
easier to control exactly what is going on. Essentially you are just
compiling exactly as you normally an executable, but instead make a .so
(with the -shared option) and including the additional .o files generated
by compiling the f2py-generated wrappers.

Hope this helps,
Gaetan

On Sat, Mar 25, 2017 at 5:38 AM, Lisandro Dalcin <dalcinl at gmail.com> wrote:

>
>
> On 22 March 2017 at 20:29, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
>>
>>   Lisandro,
>>
>>     We've had a couple questions similar to this with f2py; is there a
>> way we could add to the PETSc/SLEPc makefile rules something to allow
>> people to trivially use f2py without having to make their own (often
>> incorrect) manual command lines?
>>
>>    Thanks
>>
>>
> Barry, it is quite hard and hacky to get f2py working in the general case.
> I think the email from Gaetan in this thread proves my point.
>
> IMHO, it is easier to write a small Fortran source exposing the API to
> call using ISO_C_BINDINGS, then wrap that code with the more traditional
> C-based "static" tools (SWIG, Cython) or even "dynamically" with ctypes or
> cffi (which use dlopen'ing).
>
>
>
> --
> 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 <+966%2012%20808%200459>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170327/dde85b7d/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 1680 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170327/dde85b7d/attachment-0001.obj>


More information about the petsc-users mailing list