【发布时间】:2017-03-09 02:37:21
【问题描述】:
我正在编写一个简单的测试代码,以了解如何包装包含 openacc 区域的 fortran 代码并从 python 调用。这是代码。
module test
use iso_c_binding, only: sp => C_FLOAT, dp => C_DOUBLE, i8 => C_INT
implicit none
contains
subroutine add (a, b, n, c)
integer(kind=i8), intent(in) :: n
real(kind=dp), intent(in) :: a(n)
real(kind=dp), intent(in) :: b(n)
real(kind=dp), intent(out) :: c(n)
integer(kind=i8) :: i
!$acc enter data create(a, b, c)
do i = 1, n
c(i) = a(i) + b(i)
end do
!$acc exit data delete(a, b, c)
end subroutine add
subroutine mult (a, b, c)
real(kind=dp), intent(in) :: a
real(kind=dp), intent(in) :: b
real(kind=dp), intent(out) :: c
c = a * b
end subroutine mult
end module test
现在,如果我不使用 openacc,它可以正常工作,我可以同时使用 python 中的 add 和 mult。但是我放了openacc区域后,f2py编译得很好,但是当我尝试导入python时,我得到了以下错误
ImportError: /home/vikram/Experiments/Experiments/fortran_python/hello.cpython-35m-x86_64-linux-gnu.so: undefined symbol: GOACC_enter_exit_data
这似乎告诉我 Python 需要知道如何找到 GOACC_enter_exit_data,我看到 GOACC_enter_exit_data 在 libgomp.so.1 中。我如何告诉 python 它的路径。
【问题讨论】:
-
你的编译命令是什么?您的 f2py 是否适用于 OpenMP 程序?
-
感谢您的评论。我实际上通过使用命令 f2py -c -m --verbose --f90flags='-fopenacc -foffload=nvptx-none -foffload=-O3 -O3' hello hello.f90 -L/usr/local/cuda 解决了这个问题/lib64 -lcublas -lcudart -lgomp 显然缺少的是 lgomp。
-
你应该把它写成答案。通常不会明确链接 libgomp。
-
好的。谢谢。是的,我没想到会明确提出 libgomp 但不得不这样做。
标签: python fortran f2py openacc