我正在尝试为我不久前编写的Python实现获得一些加速,并决定为此使用f2py。我目前仍在测试一些东西,并认为我需要一些帮助,使FFTW3工作。对于第一个测试,我编写了以下子程序:
subroutine initFFT(planF, a, res, n)
implicit none
include "fftw3.f"
integer, INTENT(IN) :: n
complex(KIND=8), dimension(n) :: a, res
integer(KIND=8), intent(OUT) :: planF
call dfftw_plan_dft(planF, 1, n, a, res, FFTW_FORWARD, FFTW_MEASURE)
end subroutine initFFT
subroutine operation(a, res, n, planF)
implicit none
INCLUDE 'fftw3.f'
integer :: n
integer(KIND=8) :: planF
complex(KIND=8), dimension(n), intent(IN) :: a
complex(KIND=8), dimension(n), intent(OUT) :: res
call dfftw_execute_dft(planF, a, res)
end subroutine operation
我用这个简单的程序测试过
^{pr2}$并用
gfortran -o ftest myFun.f90 -L/usr/lib -lfftw3 -I/usr/include
一切正常,结果都是正确的。现在,我尝试用以下方式将其与f2py一起使用:
f2py -c myFun.f90 -m modf --f90flags="-L/usr/lib -lfftw3 -I/usr/include"
问题是,当我尝试在Python中导入创建的模块(使用import modf)时,收到以下错误消息:
Import Error: modf.so undefined symbol: dfftw_execute_dft_
我已经在Google上花了不少时间,但不知怎么的,到目前为止我还没有找到任何有用的东西。有人知道怎么解决这个问题吗?在
您可以尝试直接使用标志到f2py而不是通过
f90flags
?在目前,您告诉fortran编译器如何构建模块,但是f2py却不知道链接步骤。您需要的是,最后一个Python可调用模块知道fftw的存在。在
选项在Fortran文件名之前给出,如https://docs.scipy.org/doc/numpy/f2py/usage.html
相关问题 更多 >
编程相关推荐