Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
You can partition the jobs and use ParallelSubmit as here: mathematica.stackexchange.com/a/2877/5 (possible duplicate) –  rm -rf Jan 29 '13 at 21:17
add comment

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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