I saw a tutorial on how to do a distributed calculation:
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))
Why does the tutorial use a direct view? How would this be implemented with a load balanced view?
I did some benchmarking to try and figure out how well this performs.
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 )
result is pretty terrible (blue is parallel, green is serial):
that's hardly a worthy load. First you're doing vector multiplication, not true matrix to matrix multiplication. Try say, oh 10000x10000 matrices. If you have multiple cores I think you might begin to see some differences.