I would like to perform cython
files compilation in parallel.
So, I take a look at Cython.Build
source file, and find the following signature for cythonize
function:
def cythonize(module_list, exclude=None, nthreads=0, aliases=None,
quiet=False, force=False, language=None,
exclude_failures=False, **options):
And the following comment about cythonize nthreads
option:
"For parallel compilation, set the 'nthreads' option to the number of
concurrent builds."
So I tried to use this option in my setup.py
file, like that:
from setuptools import setup
from Cython.Build import cythonize
from Cython.Distutils.extension import Extension
EXTENSIONS = [Extension(...)
...
Extension(...)]
setup(name='...',
...
ext_modules=cythonize(EXTENSIONS, nthreads=8),
...)
But my .pyx
files are still compiled sequentially using 1 thread.
I do not understand what I am doing wrong here and how to use nthreads
option to perform cythonize
compilation in parallel ?
Cython builds are a two step process:
The nthreads
argument to cythonize()
controls the concurrency of the first process, but not the second.
For the second process build_ext
takes a -j
argument to control the concurrency of builds, so you can speed up your builds like this:
python setup.py build_ext -j 4
Or if you are building a wheel, you can use:
python setup.py build_ext -j 4 bdist_wheel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With