Re:Ask HN: Multiprocessing & concurrency: C, Python, Clojure...
by _delirium on Sunday October 24, 2010 @03:50AM
(#1825587)
Can't you also use OpenMP for the quick-fix "parallel map" abstraction? The typical C way of mapping an operation is to do it in a loop, and if the loop iterations don't depend on each other (as in the mapping case), you can just add a "#pragma omp parallel for" at the top of the loop to make it execute via the worker pool.
[ Parent
| on HN ]
Re:Ask HN: Multiprocessing & concurrency: C, Python, Clojure...
by sqrt17 on Sunday October 24, 2010 @08:38AM
(#1825995)
If the execution time of the function varies considerably (i.e., some of the sub-problems are faster to solve), then you want to be able to keep the other processors busy with the next sub-problems while one of them keeps gnawing at a particularly difficult one.
If the timing is very predictable, OpenMP's parallel-for construct fits your bill very nicely.
Re:Ask HN: Multiprocessing & concurrency: C, Python, Clojure...
by _delirium on Sunday October 24, 2010 @04:37PM
(#1827188)
Hmm, I thought OpenMP's worker-pool management did do that? E.g. if you have an 100-iteration loop, and have your num_threads set to 10, then it'll start up the first 10 subproblems; the first thread to finish will get the 11th, etc. If one of the first 10 is really slow, the other threads will still move on to churn on the rest of the loop iterations. Or is that not how it works?
Re:Ask HN: Multiprocessing & concurrency: C, Python, Clojure...
by sqrt17 on Sunday October 24, 2010 @05:28PM
(#1827351)
Actually, you're right. OpenMP allows you to choose between "static" scheduling (where it would just cut the 100-iteration loop into 0..24, 25..49, 50..74, 75..99 if you have four processors) and "dynamic" scheduling with a specifiable block size (where it would, for a block size of 10, first chop off four iteration blocks of 0..9, 10..19, 20..29, 30..39, and allocate the other six blocks depending on which processor wants more work first).
According to the OpenMP tutorial, the default for OMP_SCHEDULE is implementation dependent, and the gcc OpenMP implementation uses dynamic scheduling with a chunk size of 1 by default.