Multiprocessing Nested Python Loops
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**
Solution 1:
If the HeavyComputationThatIsThreadSafe1
function only uses arrays and not python objects, I would using a concurrent futures (or the python2 backport) ThreadPoolExecutor
along with Numba (or cython) with the GIL released. Otherwise use a ProcessPoolExecutor
.
See:
http://numba.pydata.org/numba-doc/latest/user/examples.html#multi-threading
You'd want to parallelize the calculation at the level of the outermost loop and and then fill output
from the chunks resulting from each thread/process. This assumes the cost of doing so is much cheaper than the computation, which should be the case.
Post a Comment for "Multiprocessing Nested Python Loops"