build:
python3 setup.py build_ext -if
using:
from parallelsort import parallelsort
import numpy as np
arr = np.random.uniform(0,100,100000000)
%timeit np.sort(arr)
%timeit parallelsort(arr)
build:
python3 setup.py build_ext -if
using:
from parallelsort import parallelsort
import numpy as np
arr = np.random.uniform(0,100,100000000)
%timeit np.sort(arr)
%timeit parallelsort(arr)
import cython | |
cimport cython | |
ctypedef fused real: | |
cython.short | |
cython.ushort | |
cython.int | |
cython.uint | |
cython.long | |
cython.ulong | |
cython.longlong | |
cython.ulonglong | |
cython.float | |
cython.double | |
cdef extern from "<parallel/algorithm>" namespace "__gnu_parallel": | |
cdef void sort[T](T first, T last) nogil | |
@cython.boundscheck(False) # turn off bounds-checking for entire function | |
@cython.wraparound(False) # turn off negative index wrapping for entire function | |
def parallelsort(real[:] a): | |
""" | |
In-place parallel sort for numpy types | |
""" | |
sort(&a[0], &a[a.shape[0]]) |
from setuptools import Extension, setup | |
from Cython.Build import cythonize | |
ext_modules = [ | |
Extension( | |
"parallelsort", | |
["parallelsort.pyx"], | |
language="c++", | |
extra_compile_args=['-fopenmp'], | |
extra_link_args=['-fopenmp'], | |
) | |
] | |
setup( | |
name='parallelsort', | |
ext_modules=cythonize(ext_modules, compiler_directives={'language_level': "3"}), | |
) |