F2py with OMP: unable to import module, undefined symbol GOMP_ *

I was hoping to use openmp to speed up my Fortran code, which I run through f2py. However, after compiling successfully, I cannot import the module into Python.

For a Fortran95 module, for example:

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

Compiled and imported using the following commands:

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

I get an error message. Error for import - compilation works fine with both f2py and gfortran directly (only get a warning about "Using deprecated NumPy APIs").

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

I get different GOMP_ * errors for different OMP directives. Without directives (but with the -openmp flag) it works.

Any help would be greatly appreciated.

+6
source share
1 answer

I was able to reproduce the error on Mac OS X (10.9.5), with gfortran installed using homebrew, and I was able to fix it by adding -lgomp to the command:

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

Added by @Mark: Note that -lgomp is an argument for f2py, not gfortran. Although it compiles with just -gomp , it requires both -gomp and -fopenmp , as described here . GOMP is a GNU openMP implementation.

+5
source

Source: https://habr.com/ru/post/981824/


All Articles