Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 使用Dask进行内存中Numpy计算的工人与线程_Multithreading_Numpy_Parallel Processing_Dask_Dask Distributed - Fatal编程技术网

Multithreading 使用Dask进行内存中Numpy计算的工人与线程

Multithreading 使用Dask进行内存中Numpy计算的工人与线程,multithreading,numpy,parallel-processing,dask,dask-distributed,Multithreading,Numpy,Parallel Processing,Dask,Dask Distributed,以下脚本用于基准测试: 来自dask.distributed import客户端 将dask.array导入为da 将numpy作为np导入 进口麻木为nb 导入时间 导入系统 N=20000 M=20000 def_np(): 返回np.random.random((N,M)).mean() @注意:准时制 定义f_nb(): 返回np.random.random((N,M)).mean() 定义f_da(): 返回da.random.random((N,M),chunks=(50005000

以下脚本用于基准测试:

来自dask.distributed import客户端
将dask.array导入为da
将numpy作为np导入
进口麻木为nb
导入时间
导入系统
N=20000
M=20000
def_np():
返回np.random.random((N,M)).mean()
@注意:准时制
定义f_nb():
返回np.random.random((N,M)).mean()
定义f_da():
返回da.random.random((N,M),chunks=(50005000)).mean().compute()
def回路(左、右、右):
ts=[]
对于范围(n)中的i:
t0=时间。时间()
f()
t1=时间。时间()
ts.append(t1-t0)
打印(f“{l}:{round(sum(ts)/n,3)}:{','.join(str(round(t,3))for t in ts)}”)
如果名称=“\uuuuu main\uuuuuuuu”:
t、 w,m=元组(sys.argv[1:]中a的int(a))
客户端=客户端(
进程=真,
每工作线程数=t,
n_工人=w,
内存限制=f'{m}GB'
)
循环(“np”,3,f_np)
环路(“nb”,3,f_nb)
循环(“da”,3,f_da)
性能比较:

# python test_np.py [Threads per Worker] [Workers] [Memory Limit]
# what: AVG: run1, run2, run3

$ python test_np.py 1 1 12
np: 4.546: 4.521 , 4.474 , 4.644
nb: 4.125: 4.296 , 3.948 , 4.132
da: 4.698: 4.911 , 4.611 , 4.573

$ python test_np.py 4 1 12
np: 4.426: 4.408 , 4.448 , 4.422
nb: 3.938: 4.205 , 3.808 , 3.802
da: 2.064: 2.032 , 2.104 , 2.055

$ python test_np.py 1 4 3
np: 4.496: 4.498 , 4.533 , 4.456
nb: 3.996: 4.274 , 3.825 , 3.89
da: 2.076: 2.109 , 2.056 , 2.064

$ python test_np.py 4 4 3
np: 4.577: 4.612 , 4.565 , 4.556
nb: 4.029: 4.368 , 3.851 , 3.869
da: 2.077: 2.097 , 2.067 , 2.068
我试图了解这些案例在工人数量和线程数量方面的区别。案例1与预期一样

我的理解是,工作线程的数量决定了并行计算的数量,而线程的数量(每个工作线程)决定了读/写操作的有效利用率(在空闲时间内)

这就是为什么我想知道为什么案例2和案例3和4一样快。或者换句话说,既然IO几乎可以忽略,因为所有内容都可以轻松地放入内存,那么为什么案例3和案例4的速度不比案例2快呢

关于观察htop中的CPU活动,案例2与案例3和4不可区分。我希望情况2与情况1相同-即只有一个活动核心


计算是在e2-standard-4(4个VCPU,16 GB内存)GCE实例上完成的

$ uname -a
Linux dask 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 GNU/Linux

$ python -V
Python 3.8.10

$ pip list | grep -E "dask|distributed|numpy|numba"
dask                2021.4.1
distributed         2021.4.1
numba               0.53.1
numpy               1.20.2