2012-08-02 29 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。