To improve my code which has one heavy loop I need a speed up. How can I implement multiprocessing for a code like this? (a is typical of size 2 and l up to 10)
for x1 in range(a**l): for x2 in range(a**l): for x3 in range(a**l): output[x1,x2,x3] = HeavyComputationThatIsThreadSafe1(x1,x2,x3)
HeavyComputationThatIsThreadSafe1over a billion times. How many seconds does a single call toHeavyComputationThatIsThreadSafe1take? Take that number, multiply it by 1073741824 and divide by the number of cores you have. That gives you the absolute best-case scenario runtime you could achieve with multiprocessing.HeavyComputationThatiIsThreadSafein the original question you linked to. Even with the data size you mention, it only takes ~8GB of memory and 45s to go over all three nested loops, if you take some reasonable optimization sets.