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

Restrict use of multiple threads for parallel processing #44

Closed
andportnoy opened this issue Oct 26, 2018 · 5 comments
Closed

Restrict use of multiple threads for parallel processing #44

andportnoy opened this issue Oct 26, 2018 · 5 comments

Comments

@andportnoy
Copy link
Collaborator

andportnoy commented Oct 26, 2018

The following works if we are the first to import NumPy:

import os
os.environ["MKL_NUM_THREADS"] = "1" 
os.environ["OMP_NUM_THREADS"] = "1" 
import numpy as np

If NumPy had already been imported, multiple threads are still being used.
More details in numpy/numpy#11826

@andportnoy
Copy link
Collaborator Author

Pandas discussion: pandas-dev/pandas#23139

@andportnoy
Copy link
Collaborator Author

Solution:

  1. Check platform.
  2. If Linux, run ldd on multiarray.so. If Mac, run otool -L on multiarray.so. Windows not supported.
  3. Try matching OpenBLAS and MKL in the output. If either is found, use ctypes inside a context manager to set the number of threads.
  4. Run computation.

References:

@andportnoy
Copy link
Collaborator Author

My current understanding is that on Macs pip installing NumPy results in OpenBLAS being installed in the .dylibs subdirectory of the NumPy directory in site-packages. So for Macs the strategy is to load the library directly (using the path provided by otool). Maybe that should be the approach in general (as opposed to using automatic resolution with ctypes.CDLL).

For now, we focus on Linux.

@andportnoy
Copy link
Collaborator Author

andportnoy commented Oct 29, 2018

Interesting: on a machine with 48 cores MKL defaults to 24 threads, OpenBLAS to all 48.

In addition, MKL sets a hard max at 24 threads (half available?).

@andportnoy
Copy link
Collaborator Author

closed as of 6b10830

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

1 participant