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

Joblib's BLAS disabling mechanism to prevent CPU over-subscription does not work #834

mgbckr opened this Issue Jan 16, 2019 · 2 comments


None yet
2 participants
Copy link

mgbckr commented Jan 16, 2019

python version: 3.6.5
joblib version: 0.13.0/1
numpy version: 1.15.4

According to Section 2.4.7 "Avoiding over-subscription of CPU ressources" joblib turns off BLAS automatically. But it does not work for me. In the following code, should not launch multiple threads. But it does. If I enable the matching environment variable as indicated in the comments, things work as they should.

#import os
#os.environ['OPENBLAS_NUM_THREADS'] = '1'
#os.environ['MKL_NUM_THREADS'] = '1'
#os.environ['NUMEXPR_NUM_THREADS'] = '1'

import numpy as np
import joblib

X = np.random.rand(100,60000) # 60: no threads, 60000: lot's of threads ;)
def func():
    for i in range(10000):
joblib.Parallel(n_jobs=2, verbose=10)(joblib.delayed(func)() for i in range(10000))

For my own scripts, I noticed that including the environment statements before numpy, scipy etc. prevents BLAS to kick in. However, in the above example importing joblib before numpy does not make a difference. Also, the documentation seems to suggest, that this only works for the 'loky' backend. However, forcing it by setting backend="loky" does not make a difference either (even if I set n_jobs=2 in which case the loky backend is definitely being used).

I can replicate the issue on 2/3 machines. On one machine it happened yesterday, today it does not. A little mysterious ;)

OS details:

VERSION="18.04.1 LTS (Bionic Beaver)"
PRETTY_NAME="Ubuntu 18.04.1 LTS"


Linux 4.15.0-43-generic x86_64

This comment has been minimized.

Copy link

ogrisel commented Jan 21, 2019

joblib.Parallel(n_jobs=1) means running in sequential mode: in this case joblib does nothing with respect to OpenMP / OpenBLAS / MKL threads.

The over-subscription protection of loky is only for the children worker processes (that are created when n_jobs >= 2).


This comment has been minimized.

Copy link

mgbckr commented Jan 21, 2019

As I mentioned. Even if I set n_jobs >= 2, this also happens. I tried again just to make sure.

Interestingly enough though, I also tried again on all of my three machines. And again, this happened only on two out of three machines.

Let me know if you need any specific info or statistics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment