7

我正在运行 Mac OS X 10.6.8 并且正在使用 Enthought Python Distribution。我希望 numpy 函数能够利用我的两个核心。我遇到了与这篇文章类似的问题:python/numpy 中的多线程 blas,但是在完成了该海报的步骤之后,我仍然遇到了同样的问题。这是我的 numpy.show_config():

lapack_opt_info:
    libraries = ['mkl_lapack95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_mc', 'mkl_mc3', 'pthread']
    library_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/lib']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/include']
blas_opt_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_mc', 'mkl_mc3', 'pthread']
    library_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/lib']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/include']
lapack_mkl_info:
    libraries = ['mkl_lapack95_lp64', 'mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_mc', 'mkl_mc3', 'pthread']
    library_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/lib']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/include']
blas_mkl_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_mc', 'mkl_mc3', 'pthread']
    library_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/lib']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/include']
mkl_info:
    libraries = ['mkl_intel_lp64', 'mkl_intel_thread', 'mkl_core', 'mkl_mc', 'mkl_mc3', 'pthread']
    library_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/lib']
    define_macros = [('SCIPY_MKL_H', None)]
    include_dirs = ['/Library/Frameworks/EPD64.framework/Versions/1.4.2/include']

与原始帖子的评论一样,我删除了设置变量的行MKL_NUM_THREADS=1。但即便如此,应该利用多线程的 numpy 和 scipy 函数一次也只使用我的一个内核。还有什么我应该改变的吗?

编辑:为了澄清,我试图让一个单一的计算,如 numpy.dot() 根据 MKL 实现自行使用多线程,我不想利用 numpy 计算释放控制的事实GIL,因此使多线程与其他功能更容易。

这是一个应该使用多线程但不在我的机器上的小脚本:

import numpy as np

a = np.random.randn(1000, 10000)
b = np.random.randn(10000, 1000)

np.dot(a, b) #this line should be multi-threaded
4

1 回答 1

7

This article似乎暗示numpy智能地使某些操作并行,这取决于操作的预测加速:

  • “如果你的 numpy/scipy 是使用其中之一编译的,那么 dot() 将在你不做任何事情的情况下并行计算(如果这更快的话)。”

根据 numpy 确定何时并行化特定 dot() 调用的启发式方法,您的小型(-ish)测试用例可能不会显示出显着的加速?也许尝试一个可笑的大操作,看看是否使用了两个核心?

附带说明一下,您的处理器/机器配置是否真的支持 BLAS?

于 2012-08-07T20:02:34.107 回答