Wang
Wang

Reputation: 8173

Modules compiled with /openmp cannot be import?

I have a very simple cython code which use prange, which works fine in linux. However, when I try to do it in Windows. I encountered a problem that it can be compiled but cannot be imported:

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

Moreover, in windows I cannot from cython.parallel import threadlocal?! strange...

Is there anyone can point a direction?

System works fine: linux64, compiler gcc, packages: Python 2.7, cython 0.16

system has problem: Win64, compiler: MSVC VS2008, packages: Python 2.7, cython 0.16

Here is my simple cython 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

Here is my 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',],),]
)

Upvotes: 1

Views: 757

Answers (2)

Rabih Kodeih
Rabih Kodeih

Reputation: 9521

Use MinGW (see this question to properly setup mingw with cython) , then update your setup.py to:

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,
)

This is working on a windows7 multi-core 64bit machine with Python 2.7 and cython 2.0.

Upvotes: 0

Wang
Wang

Reputation: 8173

Due to the VS2008 installer bug, the amd64_microsoft.vc90.openMP does not get installed into winSxS. Installing the openMP runtime will solve this problem.

see this question for detail: How to properly setup VS2008 for x64 programing?

Upvotes: 1

Related Questions