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

Controlling parallelism #28

Closed
ivirshup opened this issue Jun 26, 2023 · 4 comments · Fixed by #37
Closed

Controlling parallelism #28

ivirshup opened this issue Jun 26, 2023 · 4 comments · Fixed by #37

Comments

@ivirshup
Copy link

Was just looking at the PR over on scipy (super excited to see this moving forward!), and noticed that this library has its own global variable for parallelism.

Ideally, I would like for the number of threads used to be controlled by some higher level API like threadpoolctl.

Any thoughts on how this could be accomplished? Maybe something at the scipy level?

@alugowski
Copy link
Owner

Right, there's a parallelism argument for each method and the default value for that argument is from the fast_matrix_market.PARALLELISM global.

So writing a hook for whatever higher level API should be easy; just set that global.

Scipy itself does not have an internal system besides threadpoolctl. The small handful of threaded Python methods accept a parallelism argument like FMM does, and Ralf confirmed that this approach is ok. The workhorse parallel routines use BLAS or OpenMP, so threadpoolctl works for those.

Unless I'm missing something threadpoolctl supports those 4 libraries and that's it. If there's a way to hook into it then a PR is welcome.

@alugowski
Copy link
Owner

I opened an issue with threadpoolctl asking for a way to register arbitrary libraries: joblib/threadpoolctl#137

If there is movement on that then I'm happy to revisit this. I think it would be nice for completeness.

As of today threadpoolctl supports BLIS, OpenBLAS, MKL, and OpenMP. So they only way for FMM to support it is to rewrite the parallel logic in OpenMP. That would be terrible for a long list of reasons.

I'm not aware of other high-level APIs. So as far as I can tell there's nothing possible to do. Feel free to reopen if I missed something.

@alugowski alugowski closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2023
@alugowski alugowski reopened this Jul 11, 2023
@alugowski
Copy link
Owner

@ivirshup The threadpoolctl folks say this is out of scope for threadpoolctl because there is a way to do it with Python as is. But with their new controller API it's still possible to control FMM. I've made a PR do do this, though I'd rather wait on merging it until threadpoolctl makes a release so that we know their new API is stable.

If you'd like to test then you have to install threadpoolctl straight from github:
pip install --upgrade git+https://github.com/joblib/threadpoolctl

@ivirshup
Copy link
Author

Great! Also thanks for opening that issue with threadpoolctl! I've been wanting it to control threading levels for a bit!

And, yes makes sense to wait for the release.

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

Successfully merging a pull request may close this issue.

2 participants