An introduction to parallel programming using Python's multiprocessing module
sebastianraschka.com
sebastianraschka.com
Small sequential portions of an otherwise parallel algorithm can have huge effects on the overall running when trying to scale up.
"parconc" explains this while discussing a parallel version of k-means, talks about how things like granularity of data needs to be fine-tuned for parallel algos, and provides some nice visualizations into what the CPU's are actually doing on a timeline: http://chimera.labs.oreilly.com/books/1230000000929/ch03.htm...
Overall I think multicore is a good tool to have in your toolbox, but it seems like there needs to be a lot of tuning and effort to get good rewards for the time invested.
# Exit the completed processes
for p in processes:
p.join()
The comment should read something more like: "Wait for all the subprocesses to exit" but is that really any more helpful than just reading the code and seeing that join is called on each subprocess and connecting the dots from there?It isn't if you have been programming using threads before ,"join" is obvious then
But if you haven't and maybe you are a physicist trying to get something done in python, "p.join()" could mean anything -- "Join to what?", "Why is there no argument to join()?" "We are joining the data togther there like a list..." "It looks like we should be stopping the processes but the method is not called 'stop()' so that's not it"...
That is the problem of teaching this stuff by someone who has been programming for a while, this kind of stuff gets internalized and becomes obvious but it is not obvious to a beginner.
Also, I would suggest that the physicist in your example hire a software practitioner [who can be expected to know 'join'] to write his software correctly (rather than trying to half-ass it himself).
TypeError: list indices must be integers, not tuple
multiprocessing adds memory isolation through the CPU's protected memory.
In doubt, ask nginx how they feel about that. Then ask apache's mpn-prefork how that feels.
Event based models only shine when you are doing IO-bound tasks. They won't help you when you are chewing CPU.
Threading models in Python aren't attractive because of the GIL. If you are doing a parallel matrix operation you can only ever use one CPU because of the GIL. Not attractive.