[petsc-users] How to use f2py on a PETSc/SLEPc-based fortran code
Austin Herrema
aherrema at iastate.edu
Wed Mar 22 10:38:44 CDT 2017
Hello all,
I am trying to do as the subject line describes--use f2py to run a large
PETSc/SLEPc fortran finite element code through python. I really only need
to wrap the outermost function of the fortran code--don't need any access
to subroutines. I'll describe what I'm doing, some of which I'm not 100%
confident is correct (not much experience with f2py)--feel free to
correct/redirect any of it.
First, I'm editing the fortran code so that the top-level function is a
subroutine rather than a main program (it's my understanding that this is
required for f2py?).
I use my regular makefile (modeled after a standard SLEPc makefile from the
user guide) to compile all of the .f90/.F90 files (many of them) to .o
files using SLEPc/PETSc rules. The final linking phase fails since there
isn't a main program, but I'm just ignoring that for now since that's not
what I ultimately need...
Using a python script, I set up and run the f2py command. Right now it has
the form...
"f2py -c -m modname outer_driver.f90 file1.o file2.o file3.o..." etc.
This appears to work, but upon attempting to import, it cannot find the
SLEPc (and, I presume, PETSc) objects/functions:
>>> import mod_name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(./mod_name.so, 2): Symbol not found: _epscreate_
Referenced from: ./mod_name.so
Expected in: flat namespace
in ./mod_name.so
Based on this discussion
<http://stackoverflow.com/questions/40144031/using-f2py-on-a-fortran-code-linked-to-petsc>,
I believe I need to somehow include PETSc/SLEPc info when linking with
f2py. Is that correct? Any direction on how to do that? I don't quite
understand what the OP of that question ultimately ended up doing to get it
to work. I tried using the -I flag pointing to the slepc_common file (like
the SLEPc makefile does). The problem is that that is a file, not a
directory, which contains a number of other makefile-style variables--so it
works to include it in a makefile, but doesn't work in python. Maybe there
are only a few directories I really need to include? Or is it possible to
somehow run f2py through a makefile? I'm a bit ignorant in that realm as
well.
Thank you for any help or suggestions!
Austin
--
*Austin Herrema*
PhD Student | Graduate Research Assistant | Iowa State University
Wind Energy Science, Engineering, and Policy | Mechanical Engineering
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170322/c55f18cf/attachment.html>
More information about the petsc-users
mailing list