9

I'm using mixture submodule of sklearn module for Gaussian Mixture Model... When I run my code on a multicore system, it uses multiple cores even though I do not ask for it in the code. Is this a default behavior? And more important, how can I disable it?

Thanks

dmh
  • 1,053
  • 12
  • 26
ahmethungari
  • 2,089
  • 4
  • 19
  • 21
  • is it possible that your numpy installation is multithreaded? – prgao Oct 08 '13 at 20:10
  • hmmm. maybe. how can I check it? and how can I force it to be single threaded without reinstalling? – ahmethungari Oct 08 '13 at 20:39
  • try multiplying 2 giant matrices (A.dot(B) not A * B), like 5000x5000, and see if there's multi core usage. The multithreading depends on the library your numpy was compiled against. – prgao Oct 08 '13 at 20:41
  • Ok, you are right. I've tried what you recommended and it runs on multi cores. Is there any way to disable this behavior? – ahmethungari Oct 08 '13 at 21:00
  • how did you install your numpy library? check this out: http://stackoverflow.com/questions/17053671/python-how-do-you-stop-numpy-from-multithreading – prgao Oct 08 '13 at 21:03

2 Answers2

17

If you are using MKL then try

export MKL_NUM_THREADS=1

For Numpy with OpenBLAS:

export OPENBLAS_NUM_THREADS=1

For some versions of Numpy this variation has been suggested:

export NUMEXPR_NUM_THREADS=1

The environment variable has to be set before the script is run (setting inside the script itself does not have the desired effect). For setting threads at runtime see: Set max number of threads at runtime on numpy/openblas

See the following for identifying how your numpy is setup: How to check blas/lapack linkage in numpy/scipy?

Community
  • 1
  • 1
filitchp
  • 616
  • 9
  • 8
1

thanks @prgao

the answer is there Python: How do you stop numpy from multithreading?

setting "export MKL_NUM_THREADS=1" seems to be working

Community
  • 1
  • 1
ahmethungari
  • 2,089
  • 4
  • 19
  • 21
  • 2
    It works only if the version of numpy use use is linked against the MKL implementation of BLAS / LAPACK. For OpenBLAS, it is going to be `export OPENBLAS_NUM_THREADS=1` instead. For ATLAS you will have to recompile ATLAS to disable threading. – ogrisel Apr 24 '15 at 16:45
  • Thanx we were going crazy! – arutaku Feb 07 '17 at 14:26