So I have a bunch of functions, that don't depend on each other to do their stuff, and each of them takes quite some time. So i thought i would safe runtime if I could use Multiple Threads. For example:
axial_velocity = calc_velocity(data_axial, factors_axial)
radial_velocity = calc_velocity(data_radial, factors_radial)
circumferential_velocity = calc_velocity(data_circ, factors_circ)
All my variables so far are lists (pretty long lists too)
I have to do this for every input file, and this takes hours if there are more than 200... (I excpect about 1000+)
To reduce the runtime I tried to check compute the data as little as possible (especially sanity checks) which helped greatly, but the next improvement would be using one thread for each set of data.
I've tried something like this (oversimplyfied):
from multiprocessing import Pool
def calc_velocity(data, factor):
buffer_list = []
for index, line in enumerate(data):
buffer_list.append(data[index] * factor[index])
return buffer_list
data_axial = [1, 2, 3]
factors_axial = [3, 2, 1]
if __name__ == '__main__':
p = Pool(4)
axial_velocity = p.map(calc_velocity, args = (data_axial, factors_axial))
and:
from multiprocessing import Process
def calc_velocity(data_pack):
data = []
factor = []
data.extend(data_pack[0])
factor.extend(data_pack[1])
buffer_list = []
for index, line in enumerate(data):
buffer_list.append(data[index] * factor[index])
return buffer_list
data_axial = [1, 2, 3]
factors_axial = [3, 2, 1]
if __name__ == '__main__':
data_pack = []
data_pack.append(data_axial)
data_pack.append(factors_axial)
p = Process(target = calc_velocity, args = data_pack)
p.start()
p.join()
print p
None of these work, and I can't figure out how to make them work.