[英]Compiling cython with openMP support on OSX
我正在使用OSX v10.11.6并安装了最新版本的xcode。 所以我的默认编译器是gcc
,这真的很clang
。 我使用自制软件来安装gcc5以便我可以使用openMP,并在我的Makefiles中设置CC := g++-5
作为我在C中的源代码,我可以成功编译C源代码,并且非常简单地使用-fopenmp。
我想要做的就是用Cython与gcc5编译,这样我可以用用Cython的本地PRANGE功能,如小例子证明了这里 。 我在这个要点中写了一个最小的例子,借用了Neal Hughes页面。 当我尝试使用setup.py
编译omp_testing.pyx
,我得到一个(可能无关的)警告和致命错误:
cc1plus: warning: command line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
omp_testing.cpp:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
#error Do not use this file, it is the result of a failed Cython compilation.
^
error: command 'g++-5' failed with exit status 1
看完如何告诉distutils使用gcc? ,我试图在setup.py
设置CC
环境变量,但这不起作用。 我应该如何修改我的Cython setup.py
文件以使用g ++ - 5进行编译?
显然,Apple不久前放弃了OpenMP的支持,因此,您无法使用标准gcc编译包含此依赖关系的代码。 解决这个问题的一个好方法是安装LLVM并使用它进行编译。 这是对我有用的序列:
安装LLVM:
brew install llvm
在Open.py中包含OpenMP标志(-fopenmp -lomp):
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize, build_ext
exts = [Extension(name='name_of_your_module',
sources=['your_module.pyx'],
extra_compile_args=['-fopenmp'],
extra_link_args=['-lomp']
)]
import numpy as np
setup(name = 'name_of_your_module',
ext_modules=cythonize(exts,
include_dirs=[np.get_include()],
cmdclass={'build_ext': build_ext})
然后使用LLVM编译代码:
CC=/usr/local/opt/llvm/bin/clang++ python setup.py build_ext --inplace
这应该导致并行化的.so
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.