Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parallel builds when installing with pip? #422

Closed
jacklovell opened this issue Feb 14, 2023 · 4 comments
Closed

Support parallel builds when installing with pip? #422

jacklovell opened this issue Feb 14, 2023 · 4 comments

Comments

@jacklovell
Copy link
Contributor

Installing raysect from source using pip takes a long time (15 minutes in our Cherab CI for example), largely because the compilation of all the Cython extension modules is done in serial. This could be sped up by parallelising the build process. This is already done for the cythonize step (transpiling pyx to c), using all available cores. Doing it for the build step is pretty trivial: add the following in the setup call in setup.py:

setup(
    name="raysect",
    ...
    options={'build_ext': {'parallel': multiprocessing.cpu_count()}},
)

Or, for more explicit parallelisation, an environment variable to specify the number of parallel processes, defaulting to serial:

ncpu = os.getenv('RAYSECT_NCPU', '1')
setup(
    name="raysect",
    ...
    options={'build_ext': {'parallel': ncpu}},
)

N.B. Command line arguments to setup.py don't work well when installing via pip: passing --global-option means pip won't use wheels for any dependencies (Cython, numpy and matplotlib in particular cause problems) which is why an environment variable is preferred.

@CnlPepper
Copy link
Member

CnlPepper commented Feb 14, 2023

Have they finally added support for parallel compilation? Excellent I'll add that for the next release. Thanks for finding this I, barely have time to look at packaging etc.. anymore.

@jacklovell
Copy link
Contributor Author

jacklovell commented Feb 15, 2023

I'm pretty sure it's always been there (this is a distutils feature), but poorly documented. Difference is, in the past you'd download and extract the source tarball and run python setup.py build_ext --parallel={ncpu} for the parallel build, whereas in the brave new world of PEP517 it's deprecated to call setup.py directly and this was recommended as the alternative in a discourse.python.org thread I found.

@CnlPepper
Copy link
Member

CnlPepper commented Feb 18, 2023

I was aware that distutils supported parallel compilation (we use it in dev/build.sh), but I never found a reliable method to get it to work with pip when I last looked (years ago!). Of the options above, I think I'd just force it to always use all cores. I'll make it override-able with an environment variable.

@jacklovell
Copy link
Contributor Author

Fixed in #428

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants