Skip to content

Instantly share code, notes, and snippets.

@aphearin
Created December 22, 2016 21:31
Show Gist options
  • Save aphearin/294ed4d039d973d4448c4d9b6c65da49 to your computer and use it in GitHub Desktop.
Save aphearin/294ed4d039d973d4448c4d9b6c65da49 to your computer and use it in GitHub Desktop.
Minimal example of cython usage of prange and associated setup.py setup
from cython.parallel import prange
def c_array_f_multi(double[:] X):
cdef int N = X.shape[0]
cdef double[:] Y = np.zeros(N)
cdef int i
for i in prange(N, nogil=True):
if X[i] > 0.5:
Y[i] = c_exp(X[i])
else:
Y[i] = 0
return Y
import os
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
# This next line is my attempt to force Cython to compile with gcc5
os.environ["CC"] = "g++-5"
ext_modules=[
Extension("omp_testing",
["omp_testing.pyx"],
libraries=["m"],
extra_compile_args=["-O3", "-ffast-math", "-march=native", "-fopenmp" ],
extra_link_args=['-fopenmp']
)
]
setup(
name="omp_testing",
cmdclass={"build_ext": build_ext},
ext_modules=ext_modules
)
# compile instructions:
# python setup.py build_ext --inplace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment