python - 使用 dask 分布式时 OMP_NUM_THREADS 出错

标签 python numpy cluster-computing dask

我正在使用 distributed ,一个允许并行计算的框架。在这方面,我的主要用例是 NumPy。当我包含依赖于 np.linalg 的 NumPy 代码时,我收到了一个错误 OMP_NUM_THREADS,它与 OpenMP library 有关.

一个最小的例子:

from distributed import Executor
import numpy as np
e = Executor('144.92.142.192:8786')

def f(x, m=200, n=1000):
    A = np.random.randn(m, n)
    x = np.random.randn(n)
    #  return np.fft.fft(x)  # tested; no errors
    #  return np.random.randn(n)  # tested; no errors
    return A.dot(y).sum()  # tested; throws error below

s = [e.submit(f, x) for x in [1, 2, 3, 4]]
s = e.gather(s)

当我使用 linalg 测试时,e.gather 失败,因为每个作业都会抛出以下错误:

OMP: Error #34: System unable to allocate necessary resources for OMP thread:
OMP: System error #11: Resource temporarily unavailable
OMP: Hint: Try decreasing the value of OMP_NUM_THREADS.

我应该将 OMP_NUM_THREADS 设置为什么?

最佳答案

简答

export OMP_NUM_THREADS=1

or 

dask-worker --nthreads 1

说明

OMP_NUM_THREADS 环境变量控制许多库(包括支持 numpy.dotBLAS 库)在其计算中使用的线程数,比如矩阵乘法。

这里的冲突是您有两个相互调用的并行库,BLAS 和 dask.distributed。每个库都设计为使用与系统中可用的逻辑内核一样多的线程。

例如,如果您有八个内核,那么 dask.distributed 可能会在不同的线程上同时运行您的函数 f 八次。 f 中的 numpy.dot 函数调用每次调用将使用八个线程,导致同时运行 64 个线程。

这实际上很好,你会遇到性能下降,但一切都可以正常运行,但它会比你一次只使用八个线程慢,无论是通过限制 dask.distributed 还是通过限制 BLAS。

您的系统可能将 OMP_THREAD_LIMIT 设置为某个合理的数字,例如 16,以便在事件发生时向您发出警告。

关于python - 使用 dask 分布式时 OMP_NUM_THREADS 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39422092/

相关文章:

傻瓜式 Mysql 集群

performance - 如何调出内存异常 Spark

python - 向 matplotlib/seaborn 图中的某些单元格添加自定义边框

python - 具有多个 bool 条件或多个函数的函数?

python - 添加可能包含 'None' 条目的数组

python - 使用分布式 TensorFlow 学习 Keras 模型

转换中文字符时Java桥代码错误: 'utf-8' codec can't decode byte 0xc0 in position 0: invalid start byte

python - 用 or 逻辑重新查找

python - 从向量列表计算距离矩阵

python - 如何解决numpy中的冗余线性系统?