Say I have some Do loop that I'd like to evaluate in parallel: Do[Something, {i, 1, M}]. I'd like to split this list up into chunks which individual kernels evaluate. However, I would like to explicitly specify these chunks, which is something ParallelDo does not seem to allow for.

How does ParallelDo actually partition values of $i$ to be evaluated during a Do loop?

If I have a list $L$ where I need to access $L[i]$ at the $i$th iteration of the Do loop, how might I avoid slowdowns associated with using some large global list?


1 Answer 1


You can control the partitioning using the Method option of Parallel* functions. This is documented under Parallelize but the same option works with ParallelDo as well.

You can use

Method -> "ItemsPerEvaluation" -> k

to ask Mathematica to send k tasks to each kernel at a time.

The option

Method -> "EvaluatiosPerKernel" -> k

tells the system to communicate with each kernel at most k times (sending several tasks each time).

There's also Method -> "CoarsestGrained" which is the same as "EvaluatiosPerKernel" -> 1, i.e. breaks the computation into as many pieces as there are kernels, and Method -> "FinestGrained", which is the same as "ItemsPerEvaluation" -> 1.

Regarding your questions about processing a list: ParallelTable[..., {i, list}], ParallelMap[function, list] or ParallelCombine. Using Do is procedural programming. It's somewhat more difficult to parallelize a problem formulated in terms of Do than a problem formulated inly in terms of side-effect-less functions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.