3

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?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Roger Harris
  • 1,497
  • 1
  • 12
  • 20
  • You can partition the jobs and use ParallelSubmit as here: http://mathematica.stackexchange.com/a/2877/5 (possible duplicate) – rm -rf Jan 29 '13 at 21:17

1 Answers1

5

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.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263