Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using f2py with LAPACK called from inside a module

I am trying to wrap FORTRAN90 code using f2py by writing the following commands

gfortran -c nrt.f90
gfortran -c lu.f90
gfortran -c sqn.f90
gfortran -c csm.f90 -llapack -lblas
gfortran -c pa.f90

f2py -c nrt.f90 lu.f90 sqn.f90 csm.f90 pa.f90 -m p_avg

I call the LAPACK function zhegv() inside csm.f90. Everything compiles, but when I call ipython from the terminal

ipython --pylab

And then in ipython type

from p_avg import pa

I see

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-8181d9e1b27d> in <module>()
----> 1 from p_avg import pa

ImportError: ./p_avg.so: undefined symbol: zhegv_

Is there something else I need to do to make sure f2py can understand this LAPACK function call? I see other people have asked about using f2py directly with LAPACK modules, but here I am using a LAPACK function from within another piece of FORTRAN code.

Thank you.

Update: When I try the command suggested in the comments by typing the following at the terminal,

f2py -L/usr/lib/lapack -llapack -c nrt.f90 lu.f90 sqn.f90 csm.f90 pa.f90 -m p_avg 

or

f2py -L/usr/lib/ -llapack -c nrt.f90 lu.f90 sqn.f90 csm.f90 pa.f90 -m p_avg

And then typing the following in ipython,

from p_avg import pa

I get

----------------------------------------------------------------    -----------
ImportError                               Traceback (most recent    call last)
<ipython-input-1-8181d9e1b27d> in <module>()
----> 1 from p_avg import pa

ImportError: No module named p_avg
like image 336
Impossibear Avatar asked Dec 31 '25 02:12

Impossibear


1 Answers

In this case, you can indeed write

f2py -L/usr/lib/ -llapack -c nrt.f90 lu.f90 sqn.f90 csm.f90 pa.f90 -m p_avg

but you need to make sure the lapack development library is installed. When I only had liblapack3 installed, the above command didn't work.

like image 96
Impossibear Avatar answered Jan 02 '26 14:01

Impossibear



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!