I was hoping to use openmp to speed up my Fortran code that I run through f2py. However, after compiling succesfully, I can't import the module in Python.
For a Fortran95 module like this:
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 with these commands:
f2py -m SOmod --fcompiler=gnu95 --f90flags='-march=native -O3 -fopenmp' -c SOtest.f95
python2 -c "import SOmod"
I get an error. The error is for the import - compiling works fine both with f2py or gfortran directly (only get a warning about 'Using deprecated NumPy API').
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 -openmp flag) it works.
Any help would be greatly appreciated.
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
, both -gomp
and -fopenmp
are needed for it to be parallel, as described here. GOMP is the GNU openMP implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With