1

I love numpy because multi cores are automatically used on vector operation.

But, I recently noticed that only 4 cores are used although my machine has 8 cores.

enter image description here

Why doesn't numpy use all cores in the machine? Is it possible to let numpy use more cores on numpy's vector operation?

I'm using Mac OSX 10.8.

Update

np.show_config() shows below:

lapack_opt_info:
    libraries = ['mkl_lapack95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/include']
blas_opt_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/include']
openblas_lapack_info:
  NOT AVAILABLE
lapack_mkl_info:
    libraries = ['mkl_lapack95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/include']
blas_mkl_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/include']
mkl_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'iomp5', 'pthread']
    library_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/lib']
    define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
    include_dirs = ['/Users/john/.pyenv/versions/anaconda-2.0.1/include']
2
  • "I love numpy because multi cores are automatically used on vector operation." - this is only true for certain functions that call BLAS/LAPACK library functions (e.g. matrix multiplication). This isn't a feature of numpy itself, but rather depends on which BLAS/LAPACK libraries numpy is linked against at runtime. What is the output of numpy.show_config()? Commented Apr 27, 2016 at 9:26
  • @ali_m Thank you. Please see updated comment. Commented Apr 27, 2016 at 11:36

1 Answer 1

2

MKL, ideally already uses, an optimized number of threads for your system. You can check those like this:

python -c "import ctypes; mkl_rt = ctypes.CDLL('mkl_rt.dll'); print mkl_rt.mkl_get_max_threads()"

If you need to change it you might want to change MKL_NUM_THREADS environment variable:

python -c "import ctypes; mkl_rt = ctypes.CDLL('mkl_rt.dll'); print mkl_rt.mkl_get_max_threads()"

For more on MKL multi-threading check this, and the API.

I'm quoting Anton Malakhov, from Intel. You might want to check that question (Configure number of processors available to MKL NumPy) since it's very similar to yours.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much! But, OSError: dlopen(mkl_rt.dll, 6): image not found happens. I've tried mkl_rt.dylib, mkl_rt.so, and mkl_rt.lib. Both of them occurs the same error.
@rkjt50r983 I think it's because it is failing in finding them. The path will depend on your system but you should be able to locate it in your Python installation than here: Lib\site-packages\numpy\core
@rkjt50r983 Just noticed you are on Anaconda. You might want to take a look at this if you are getting Fatal Error with the above recipe (I have the same problem in WinPython). Link: github.com/numpy/numpy/issues/6923

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.