gpt4 book ai didi

python - numpy向量运算的核心使用上限

转载 作者:行者123 更新时间:2023-12-01 03:59:21 24 4
gpt4 key购买 nike

我喜欢 numpy,因为向量运算会自动使用多核。

但是,我最近注意到,尽管我的机器有 8 个核心,但只使用了 4 个核心。

enter image description here

为什么 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']

最佳答案

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()"

有关 MKL 多线程检查的更多信息 this ,以及 API .

我引用Anton Malakhov ,来自英特尔。您可能想检查该问题(配置 MKL NumPy 可用的处理器数量),因为它与您的问题非常相似。

关于python - numpy向量运算的核心使用上限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36884474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com