({{, (RefLink[ParallelDo, paclet:ref/ParallelDo])[expr,{(Subscript[i, max])}]
evaluates expr in parallel (Subscript[i, max]) times. }, {, (RefLink[ParallelDo, paclet:ref/ParallelDo])[expr,{i,(Subscript[i, max])}]
evaluates expr in parallel with the variable i successively taking on the values 1 through (Subscript[i, max]) (in steps of 1). }, {, (RefLink[ParallelDo, paclet:ref/ParallelDo])[expr,{i,(Subscript[i, min]),(Subscript[i, max])}] 
starts with i=(Subscript[i, min]). }, {, (RefLink[ParallelDo, paclet:ref/ParallelDo])[expr,{i,(Subscript[i, min]),(Subscript[i, max]),di}]
uses steps di. }, {, (RefLink[ParallelDo, paclet:ref/ParallelDo])[expr,{i,{(Subscript[i, 1]),(Subscript[i, 2]),…}}] 
uses the successive values (Subscript[i, 1]), (Subscript[i, 2]), ….}, {, (RefLink[ParallelDo, paclet:ref/ParallelDo])[expr,{i,(Subscript[i, min]),(Subscript[i, max])},{j,(Subscript[j, min]),(Subscript[j, max])},…]
evaluates expr looping in parallel over different values of j, etc. for each i. }})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[ParallelDo, paclet:ref/ParallelDo]) is a parallel version of (RefLink[Do, paclet:ref/Do]) that automatically distributes different evaluations of expr among different kernels and processors.

If side effects involve unshared variables, they will in general work differently than in (RefLink[Do, paclet:ref/Do]).

(RefLink[Parallelize, paclet:ref/Parallelize])[(RefLink[Do, paclet:ref/Do])[expr,iter, …]] is equivalent to (RefLink[ParallelDo, paclet:ref/ParallelDo])[expr,iter,…].

(RefLink[ParallelDo, paclet:ref/ParallelDo]) takes the same (RefLink[Method, paclet:ref/Method]) option as (RefLink[Parallelize, paclet:ref/Parallelize]).

(RefLink[ParallelDo, paclet:ref/ParallelDo]) takes the same (RefLink[DistributedContexts, paclet:ref/DistributedContexts]) option as (RefLink[ParallelTable, paclet:ref/ParallelTable]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (14)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

(RefLink[ParallelDo, paclet:ref/ParallelDo]) works like (RefLink[Do, paclet:ref/Do]), but in parallel:

Do[Pause[1];f[i],{i,4}]//AbsoluteTiming

ParallelDo[Pause[1];f[i],{i,4}]//AbsoluteTiming

No results are returned by (RefLink[ParallelDo, paclet:ref/ParallelDo]):

ParallelDo[Print[i],{i,4}]

Use a shared variable to communicate results found to the master kernel:

SetSharedVariable[pr]

pr={};
ParallelDo[If[PrimeQ[2^i-1],AppendTo[pr,i]],{i,2000,4000}]
pr

OpenersExampleSection1(Spacer1)Options  (7)

OpenersExampleSubsection0(Spacer1)Method  (2)

Calculations with vastly differing runtimes should be parallelized as finely as possible:

ParallelDo[If[PrimeQ[2^i-1],Print[i]],{i,4000,5000},Method->"FinestGrained"]

A large number of simple calculations should be distributed into as few batches as possible:

BinCounts[ParallelMap[Mod[Floor[#*Pi],10]&,Range[10000],Method->"CoarsestGrained"],{0,10}]

OpenersExampleSubsection1(Spacer1)DistributedContexts  (5)

By default, definitions in the current context are distributed automatically:

remote[x_]:={$KernelID,x^3}

ParallelDo[Print[remote[i]],{i,4}]

Do not distribute any definitions of functions:

kid:=$KernelID

ParallelDo[Print[kid],{i,4},DistributedContexts->None]

Distribute definitions for all symbols in all contexts appearing in a parallel computation:

a`kid:=$KernelID

ParallelDo[Print[a`kid],{i,4},DistributedContexts->Automatic]

Distribute only definitions in the given contexts:

b`kid:=$KernelID

ParallelDo[Print[b`kid],{i,4},DistributedContexts->{"a`"}]

Restore the value of the (RefLink[DistributedContexts, paclet:ref/DistributedContexts]) option to its default:

SetOptions[ParallelDo,DistributedContexts:>$DistributedContexts]

OpenersExampleSection2(Spacer1)Applications  (1)

Generate a number of animation frames and save them to individual files:

With[{frames=60,R=12},
ParallelDo[
Export["drum-"<>ToString[PaddedForm[t,3,NumberPadding->"0"]]<>".gif",RevolutionPlot3D[Sin[t/frames*2*Pi]BesselJ[0,r],{r,0,R},PlotRange->{{-R,R},{-R,R},{-1,1}}]]
,{t,0,frames-1}]
]

Import every 5(^th) file and display it:

sample=FileNames["drum-*.gif"][[1;;-1;;5]]

GraphicsGrid[Partition[Import/@sample,4]]

OpenersExampleSection3(Spacer1)Properties & Relations  (1)

(RefLink[ParallelDo, paclet:ref/ParallelDo]) performs the same iterations as (RefLink[ParallelTable, paclet:ref/ParallelTable]), but does not return the values:

ParallelTable[Print[i];i,{i,4}]

ParallelDo[Print[i];i,{i,4}]

OpenersExampleSection4(Spacer1)Possible Issues  (2)

A function used that is not known on the parallel kernels has no effect:

fprint[n_]:=If[PrimeQ[2^n-1],Print[{n,$KernelID}]]

ParallelDo[fprint[i],{i,2000,3000},DistributedContexts->None]

Define the function on all parallel kernels:

DistributeDefinitions[fprint];

The function is now evaluated on the parallel kernels:

ParallelDo[fprint[i],{i,2000,3000},DistributedContexts->None]

Definitions of functions in the current context are distributed automatically:

gprint[n_]:=If[PrimeQ[2^n-1],Print[{n,$KernelID}]]

ParallelDo[gprint[i],{i,2000,3000}]

Side effects are local to each parallel kernel:

i=0;

ParallelDo[i++,{5}];i

Use a shared variable to support global side effects:

SetSharedVariable[j]; j=0;

ParallelDo[j++,{5}];j

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Do, paclet:ref/Do])  ▪  (RefLink[ParallelTable, paclet:ref/ParallelTable])  ▪  (RefLink[ParallelSum, paclet:ref/ParallelSum])  ▪  (RefLink[Parallelize, paclet:ref/Parallelize])  ▪  (RefLink[ParallelTry, paclet:ref/ParallelTry])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Data Parallelism, paclet:guide/DataParallelism])}})}})