For maintainability purposes, my impulse is to simply use parallel processing all the time. For simple loops it sounds like there is overhead which could actually slow the function, and presumably for loops where order of execution makes a difference it is a mistake.
How do you decide when to use parallel processing and when to avoid it?
Things that would cause problems:
But more importantly; do you need it? In many cases it is overkill, and threading always has a slight overhead (the total CPU time increases, even if the elapsed time decreases). Now; if you already in a highly threaded environment (such as a busy web-server), this isn’t going to help!
There are a couple of scenarios where it comes into its own, usually when the elapsed time is more important than the overall CPU time – so very useful at the client, or on some web-server scenarios. It is especially useful if the state is immutable, so it is pretty trivial to tear the work apart and put the result back together again. There are some great examples of processing fractals etc, or other CPU-intensive work, with
Parallel.