Python Import error for f2py modules compiled with OpenMP

时光总嘲笑我的痴心妄想 提交于 2020-01-06 23:19:49

问题


I'm currently experiencing an issue in wrapping some Fortran subroutines for use in a python3 script. This issue has only come up since I have attempted to use OpenMP in the subroutines.

For example, if I compile a module 'test.pyd' using f2py -c -m --fcompiler=gfortran --compiler=mingw32 --f90flags='-fopenmp' test test.f90 -lgomp, in which 'test.f90' is a Fortran subroutine which contains a parallelized loop, upon attempting to import this module into my script, I encounter ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed..

Removing the -fopenmp flag in compiling, or the !$omp comments in the Fortran subroutine remove this error.

Changing the subroutine to a roughly equivalent Fortran program, the program compiles to a .exe and runs correctly in parallel.

I'm on a Windows 10 platform, with an AMD64 processor, using GNU Fortran and C compilers from TDM-GCC


回答1:


I just tried your build command, and it looks prefectly fine. I am myself able to run a parallel subroutine from a python module compiled just the way you are doing.

How are you executing the python code that is using your module? I think the problem is that you don't have the openmp dll (which is named libgomp-1.dll) in your path

I would advise you to run (from a bash shell) :

where libgomp-1.dll

If the command can't find it, then you should probably add the path to your openmp dll (which is usually "C:\tools\mingw64\bin\") to your PATH.

In order to do this, you can use:

export PATH=$PATH:C:\tools\mingw64\bin\ && python script_using_module.py

There is a good chance the way you are executing your python code doesn't account properly for the path, since you can run the parallel executable without a problem.



来源:https://stackoverflow.com/questions/44957887/python-import-error-for-f2py-modules-compiled-with-openmp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!