A public relations problem
A public relations problem
Posted Jul 13, 2015 13:59 UTC (Mon) by arvidma (subscriber, #6353)In reply to: A public relations problem by Kwi
Parent article: A better story for multi-core Python
The problem itself is super easy to parallelize, the tree is static at the time of traversal, there are no cross-branch references and you only modify branch-local data (in the nodes). You spin-off a thread per first-level branch (or second level branch if you want to use moar cores), wait for the recursion to trickle down and up again and summarize each thread-result on the top node when they are finished.
Problem is, only one thread at the time is active, due to GIL. Using the multiprocessing module is of no help, since that means you have to serialize the full tree in one chunk per process, copy each chunk to its new context, deserialize the chunks in every new context, reserialize it when you're finished, copy back to main context and then deserialize again... Unless the computations per node are extremely heavy, you lose way more from the overhead than you gain from the threads.
I would very much appreciate if this type of problem could be handled efficiently in Python.
