2012-08-02 62 views
1

我有一个非常简单的使用prange的cython代码,它在linux中工作正常。但是,当我尝试在Windows中执行此操作时。我遇到一个问题,它可以被编译,但不能输入:使用/ openmp编译的模块不能被导入?

ImportError: DLL load failed: This application has failed to start because the a 
pplication configuration is incorrect. Reinstalling the application may fix this 
problem. 

此外,在Windows我不能from cython.parallel import threadlocal?!奇怪......

有没有人可以指出方向?

系统工作正常:LINUX64,编译器GCC,包装:的Python 2.7,用Cython 0.16

系统有问题:Win64的,编译器:MSVC VS2008,包装:Python 2.7版,cython 0.16

这是我简单的cyx pyx:

cimport cython 
from cython.parallel import prange 

def f(int n): 
    cdef int i 
    cdef int sum = 0 
    for i in prange(n, nogil=True): 
     sum += i 
    print sum 

这里是我的setup.py:

from distutils.core import setup 
from distutils.extension import Extension 
from Cython.Distutils import build_ext 
import numpy as np 


setup(
    cmdclass = {'build_ext': build_ext}, 
    include_dirs = [np.get_include()], 
    ext_modules = [Extension("pcython1", ["pcython1.pyx"],extra_compile_args=['/openmp',],),] 
) 
+0

如果将prange替换为范围,代码是否可以在Windows下正常工作? – DaveP 2012-08-03 07:02:09

+0

@DaveP感谢您的回复! 没有'/ openmp','range'和'prange'都可以工作。有了它,它们都不起作用。 – Wang 2012-08-04 14:16:04

+0

如果系统没有安装'MS visual studio',但只安装了'VC++ redustributable',它可以正常工作......困惑...... CPU范围与'prange'版本完全不同。所以openMP正在工作,只是它不能在安装了调试DLL的系统上工作,我猜。 – Wang 2012-08-04 15:06:47

回答

0

使用MinGW(见this question正确与用Cython设置MinGW的),然后更新您的setup.py到:

from distutils.core import setup 
from distutils.extension import Extension 
from Cython.Distutils import build_ext 
import numpy as np 

ext_modules = [Extension("convolve_cy", ["convolve_cy.pyx"], 
         extra_compile_args = ["-O3", "-fopenmp"], 
         extra_link_args=["-fopenmp"])] 

setup (
    name = 'performance test app', 
    cmdclass = {'build_ext': build_ext}, 
    include_dirs = [np.get_include()], 
    ext_modules = ext_modules, 
) 

这是工作的一个windows7多核64位机器与Python 2.7和cython 2.0。