我喜欢numpy因为多核会自动用于矢量操作。
但是,我最近注意到虽然我的机器有8个核心,但只使用了4个核心。
为什么numpy不使用机器中的所有核心?是否有可能让numpy在numpy的向量操作上使用更多内核?
我正在使用Mac OSX 10.8。
np.show_config()
如下所示:
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']
答案 0 :(得分:2)
MKL
已经为您的系统使用了优化的线程数。您可以查看以下内容:
python -c "import ctypes; mkl_rt = ctypes.CDLL('mkl_rt.dll'); print mkl_rt.mkl_get_max_threads()"
如果您需要更改它,您可能想要更改MKL_NUM_THREADS环境变量:
python -c "import ctypes; mkl_rt = ctypes.CDLL('mkl_rt.dll'); print mkl_rt.mkl_get_max_threads()"
我引用了英特尔的Anton Malakhov。您可能想要检查该问题(配置MKL NumPy可用的处理器数量),因为它与您的非常相似。