我看到了一个关于如何进行分布式计算的教程:
def parallel_dot(dview, A, B):
dview.scatter('A', A)
dview['B'] = B
dview.execute('C = numpy.dot(A, B)')
return dview.gather('C')
np.allclose(parallel_dot(dview, A, B),
np.dot(A, B))
为什么教程使用直接视图?这将如何通过负载平衡视图实现?
我做了一些基准测试,试图弄清楚它的性能如何。
t1 = []
t2 = []
for ii in range(10, 1000, 10):
A = np.random.rand(10000, ii).astype(np.longdouble).T
B = np.random.rand(10000, 100).astype(np.longdouble)
t_ = time.time()
parallel_dot(dview, A, B).get()
t1.append(time.time() - t_)
t_ = time.time()
np.dot(A, B)
t2.append(time.time() - t_)
plt.plot( range(10, 1000, 10), t1 )
plt.plot( range(10, 1000, 10), t2 )
结果非常糟糕(蓝色是并行的,绿色是串行的):