gpt4 book ai didi

python - 带有 OMP : can't import module, undefined symbol GOMP_* 的 f2py

转载 作者:太空狗 更新时间:2023-10-30 00:02:39 26 4
gpt4 key购买 nike

我希望使用 openmp 来加速我通过 f2py 运行的 Fortran 代码。但是,编译成功后,我无法在Python中导入模块。

对于像这样的 Fortran95 模块:

module test
implicit none
contains
subroutine readygo()
real(kind = 8), dimension(10000) :: q
!$OMP WORKSHARE
q = 7
!$OMP END WORKSHARE
end subroutine
end module

使用这些命令编译和导入:

f2py -m SOmod --fcompiler=gnu95 --f90flags='-march=native -O3 -fopenmp' -c SOtest.f95
python2 -c "import SOmod"

我得到一个错误。错误是针对导入的 - 直接使用 f2py 或 gfortran 编译工作正常(仅收到有关“使用已弃用的 NumPy API”的警告)。

Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: ./SOmod.so: undefined symbol: GOMP_barrier

对于不同的 OMP 指令,我得到不同的 GOMP_* 错误。没有指令(但带有 -openmp 标志)它可以工作。

如有任何帮助,我们将不胜感激。

最佳答案

我能够在 Mac OS X (10.9.5) 上重现错误,使用自制软件安装了 gfortran,并且我能够通过添加 -lgomp 来修复它> 命令:

f2py -m SOmod --fcompiler=gnu95 --f90flags='-march=native -O3 -fopenmp' -lgomp -c SOtest.f95

@Mark 添加:请注意,-lgomp 是 f2py 的参数,而不是 gfortran。尽管它仅使用 -gomp 进行编译,但同时需要 -gomp-fopenmp 才能使其并行,如 here 所述. GOMP 是 GNU openMP 实现。

关于python - 带有 OMP : can't import module, undefined symbol GOMP_* 的 f2py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28258165/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com