I am able to compile the minimal working example below in Fortran which uses Openmp and run to give the expected result (prints 1).
subroutine test
use omp_lib
write(*,*) omp_get_num_threads()
end subroutine
However using this in python with f2py gives the error:
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
I have used the dependency walker to test if the issue is in linking to the openmp dll, however the following .dll is linked in both the fortran executable and the .pyd compiled from f2py:
c:\tdm-gcc-64\bin\LIBGOMP_64-1.DLL
Therefore I am confused as to why python would fail to load the .dll, as it appears to be linked correctly from f2py. The f2py command that I'm using to generate the .pyd is
python -m numpy.f2py -c -m %output% %input%.f90 --fcompiler=gnu95 --compiler=mingw32 --f90flags="-fopenmp " -lgomp
Any help would be greatly appreciated, thanks.
EDIT: I have tested this with another windows PC with the same installation setup, and get the same error message. Am I missing something?
EDIT 2: Apparently this program wouldn't actually work in f2py, so is bad example. My apologies. I'm actually working with subroutines, which are able to work with f2py correctly so long as no openmp commands are present.
EDIT 3: I have replaced the example code to be a subroutine instead of program due to feedback from Pierre de Buyl, though this makes no difference to my question.