I am trying to multiply each column of a matrix by a vector element-wise.
I have a serial solution that works correctly.
for i in range(0,temp.shape[0]):
for j in range(0,temp.shape[1]):
temp[i,j] = temp[i,j] * h[i,0]
Below is the parallel solution that works for what i am trying to do, but does not return the same matrix as the above code.
def mv_mult(start_col,end_col,M,V):
for i in range(0,M.shape[0]):
for j in range(start_col,end_col):
M[i,j] = M[i,j] * V[i,0]
num_threads = multiprocessing.cpu_count()
threads = []
extra = temp.shape[1] % num_threads
start_col = 0
jump = temp.shape[1] / num_threads
for i in range(0,num_threads):
print 'starting thread ', i
if (i < extra)
args = start_col, start_col+jump+1,temp,h
p = multiprocessing.Process(target=mv_mult,args=args)
p.start()
threads.append(p)
start_col += jump+1
else:
args = start_col, start_col+jump,temp,h
p = multiprocessing.Process(target=mv_mult,args=args)
p.start()
threads.append(p)
start_col += jump
for i in threads:
i.join()
I am relatively new to Python, but as far as I know everything is pass by reference, so the temp matrix passed to each new process is the same object, so it should work the same as the serial solution, minus the fact that it is split up by column.
Any ideas as to why it is not working?