({{, (RefLink[ParallelTable, paclet:ref/ParallelTable])[expr,{(Subscript[i, max])}]
generates in parallel a list of (Subscript[i, max]) copies of expr.}, {, (RefLink[ParallelTable, paclet:ref/ParallelTable])[expr,{i,(Subscript[i, max])}]
generates in parallel a list of the values of expr when i runs from 1 to (Subscript[i, max]). }, {, (RefLink[ParallelTable, paclet:ref/ParallelTable])[expr,{i,(Subscript[i, min]),(Subscript[i, max])}]
starts with i=(Subscript[i, min]). }, {, (RefLink[ParallelTable, paclet:ref/ParallelTable])[expr,{i,(Subscript[i, min]),(Subscript[i, max]),di}]
uses steps di. }, {, (RefLink[ParallelTable, paclet:ref/ParallelTable])[expr,{i,{(Subscript[i, 1]),(Subscript[i, 2]),…}}] 
uses the successive values (Subscript[i, 1]), (Subscript[i, 2]), ….}, {, (RefLink[ParallelTable, paclet:ref/ParallelTable])[expr,{i,(Subscript[i, min]),(Subscript[i, max])},{j,(Subscript[j, min]),(Subscript[j, max])},…]
gives a nested list. The list associated with i is outermost.}})

OpenersNotesSection(Spacer1)Details and Options

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

(RefLink[ParallelTable, paclet:ref/ParallelTable]) will give the same results as (RefLink[Table, paclet:ref/Table]), except for side effects during the computation.

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

If an instance of (RefLink[ParallelTable, paclet:ref/ParallelTable]) cannot be parallelized it is evaluated using (RefLink[Table, paclet:ref/Table]).

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

The (RefLink[DistributedContexts, paclet:ref/DistributedContexts]) option for (RefLink[ParallelTable, paclet:ref/ParallelTable]) specifies which symbols appearing in expr have their definitions automatically distributed to all available kernels before the computation.

The default value is (RefLink[DistributedContexts, paclet:ref/DistributedContexts]):>(RefLink[$DistributedContexts, paclet:ref/$DistributedContexts]) with (RefLink[$DistributedContexts, paclet:ref/$DistributedContexts]):=(RefLink[$Context, paclet:ref/$Context]), which distributes definitions of all symbols in the current context, but does not distribute definitions of symbols from packages.

OpenersPrimaryExamplesSection(Spacer1)Examples  (43)

OpenersExampleSection0(Spacer1)Basic Examples  (5)

(RefLink[ParallelTable, paclet:ref/ParallelTable]) works like (RefLink[Table, paclet:ref/Table]), but in parallel:

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

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

A table of the first 10 squares:

ParallelTable[i^2,{i,10}]

A table with i running from 0 to 20 in steps of 2:

ParallelTable[f[i],{i,0,20,2}]

Make a 4×3 matrix:

ParallelTable[10i+j,{i,4},{j,3}]

MatrixForm[%]

Plot a table:

ListPlot[ParallelTable[Total[FactorInteger[2^i-1][[All,2]]],{i,150,190}]]

OpenersExampleSection1(Spacer1)Scope  (5)

The index in the table can run backward:

ParallelTable[f[i],{i,10,-5,-2}]

Make a triangular array:

ParallelTable[10i+j,{i,5},{j,i}]

TableForm[%]

Make a 3x2x4 array, or tensor:

ParallelTable[100i+10j+k,{i,3},{j,2},{k,4}]

Iterate over an existing list:

ParallelTable[Sqrt[x], {x, {1,4,9,16}}]

Make an array from existing lists:

ParallelTable[j^(1/i), {i, {1,2,4}}, {j, {1,4,9}}]

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (1)

The table index can have symbolic values:

ParallelTable[2^x+x,{x,a,a+5n,n}]

OpenersExampleSection3(Spacer1)Options  (11)

OpenersExampleSubsection0(Spacer1)Method  (6)

Break the computation into the smallest possible subunits:

ParallelTable[Labeled[Framed[i],$KernelID],{i,10},Method->"FinestGrained"]

Break the computation into as many pieces as there are available kernels:

ParallelTable[Labeled[Framed[i],$KernelID],{i,10},Method->"CoarsestGrained"]

Break the computation into at most 2 evaluations per kernel for the entire job:

ParallelTable[Labeled[Framed[i],$KernelID],{i,12},Method->"EvaluationsPerKernel"->2]

Break the computation into evaluations of at most 5 elements each:

ParallelTable[Labeled[Framed[i],$KernelID],{i,18},Method->"ItemsPerEvaluation"->5]

The default option setting balances evaluation size and number of evaluations:

ParallelTable[Labeled[Framed[i],$KernelID],{i,18},Method->Automatic]

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

ParallelTable[{i,PrimeQ[2^i-1]},{i,4410,4430},Method->"FinestGrained"]

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

BinCounts[ParallelTable[Mod[Floor[i*Pi],10],{i,10000},Method->"CoarsestGrained"],{0,10}]

OpenersExampleSubsection1(Spacer1)DistributedContexts  (5)

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

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

ParallelTable[remote[i],{i,4}]

Do not distribute any definitions of functions:

local[x_]:={$KernelID,x^2}

ParallelTable[local[i],{i,4},DistributedContexts->None]

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

a`f[x_]:={$KernelID,x}

ParallelTable[a`f[i],{i,4},DistributedContexts->Automatic]

Distribute only definitions in the given contexts:

b`g[x_]:={$KernelID,-x}

ParallelTable[b`g[i],{i,4},DistributedContexts->{"a`"}]

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

SetOptions[ParallelTable,DistributedContexts:>$DistributedContexts]

OpenersExampleSection4(Spacer1)Applications  (6)

Solve and plot a differential equation for many initial conditions and animate the results:

eqn=D[z[t,s],t,t]==-((z[t,s])/(((((z[t,s])^2)+((((1/2) (1+0.1 Sin[2 Pi t])))^2)))^(3/2)));

sols=ParallelTable[localsol=NDSolve[{eqn,z[0,s]==param s,Derivative[1,0][z][0,s]==param},z,{t,0,10}, {s,1,2}]; 
Plot3D[Evaluate[z[tp, z0]/.localsol],{tp,0,10},{z0,1,2},PlotRange->{-5,5},PlotLabel->param], 
{param, -1,1,0.1}];

ListAnimate[sols]

Explore different parameter values for the sine-Gordon equation in two spatial dimensions:

With[{L=4,dz=0.25},
sols=ParallelTable[
localsol=Quiet@NDSolve[{D[u[t,x,y], t, t] == D[u[t,x,y], x,x] + D[u[t, x, y], y, y] + Sin[u[t,x,y]], u[t,-L, y] == u[t, L, y], u[t, x, -L] == u[t, x, L], u[0,x, y] == a Exp[-(b x^2 + y^2)], Derivative[1,0,0][u][0,x,y] == 0}, u, {t,0,L/2}, {x,-L,L},{y,-L,L}]; 
Plot3D[Evaluate[u[L/2, x, y] /. First[localsol]], {x,-L,L},{y,-L,L}, PlotRange-> {{-L,L},{-L,L}, {-dz, dz}},Axes->None,PlotLabel->{a,b}], {a, -0.5, 0.5, 0.2},{b,0.8,1.2,.1},Method->"FinestGrained"]
];

GraphicsGrid[sols]

Apply different algorithms to the same set of data:

img=;

Apply a list of different filters to the same image and display the result:

filters={Identity,Sharpen, Blur,GaussianFilter[#,3]&,LaplacianFilter[#,1]&,LaplacianGaussianFilter[#,2]&,
GradientFilter[#,2]&,MedianFilter[#,5]&,
ImageConvolve[#,BoxMatrix[1]/9]&};

ParallelTable[Tooltip[filter[img],filter],{filter,filters}]

Or apply a list of effects:

ParallelTable[ImageEffect[img, effect],{effect,{"Charcoal","Embossing","Solarization"}}]

Generate 10 frames from an animation and save them to individual files:

frames[i_,f_,R_]:=Module[{frame},
Do[frame=RevolutionPlot3D[Sin[t/(10f)*2*Pi]BesselJ[0,r],{r,0,R},PlotRange->{{-R,R},{-R,R},{-1,1}},Axes->None];
Export["drum-"<>ToString[PaddedForm[t,3,NumberPadding->"0"]]<>".gif",frame]
,{t,10i+1,10(i+1)}
];
frame
];

Run several batches in parallel:

samples=With[{batches=8},ParallelTable[frames[i,batches,11],{i,0,batches-1}]];

Each run returns one frame which can be used for checking the correctness:

samples

Remove the generated files:

DeleteFile[FileNames["drum-*.gif"]]

Tabulate histograms of word lengths in various languages:

languages=DictionaryLookup[All];Length[languages]

hist=ParallelTable[Histogram[StringLength/@DictionaryLookup[{l,All}],{1,25,1},PlotLabel->l,PlotRange->{{0,25},All},PerformanceGoal->"Speed"],{l,languages}];

Show the results in a grid:

GraphicsGrid[Partition[hist,3],ImageSize->500]

Quickly show the evaluation of several nontrivial cellular automata:

data=Select[ParallelTable[Graphics3D[{Cuboid/@Position[CellularAutomaton[{n, {2, 1}, {1, 1,1}},{{{{1}}},0},{{{8}}}],1]},Boxed->False],{n,2,80,5}],Length[#[[1,-1]]]>50&];

GraphicsGrid[Partition[data,3],Frame->All,ImageSize->500]

OpenersExampleSection5(Spacer1)Properties & Relations  (10)

Parallelization happens along the outermost (first) index:

ParallelTable[Labeled[Framed[f[i,j]],$KernelID],{i,4},{j,i}]

Using multiple iteration specifications is equivalent to nesting (RefLink[Table, paclet:ref/Table]) functions:

ParallelTable[i+j,{i,3},{j,i}]

ParallelTable[Table[i+j,{j,i}],{i,3}]

(RefLink[ParallelDo, paclet:ref/ParallelDo]) evaluates the same sequence of expressions as (RefLink[ParallelTable, paclet:ref/ParallelTable]):

ParallelDo[Print[i^i],{i,3}]

ParallelTable[i^i,{i,3}]

(RefLink[ParallelSum, paclet:ref/ParallelSum]) effectively applies (RefLink[Plus, paclet:ref/Plus]) to results from (RefLink[ParallelTable, paclet:ref/ParallelTable]):

ParallelSum[x^i,{i,3}]

ParallelTable[x^i,{i,3}]

(RefLink[ParallelArray, paclet:ref/ParallelArray]) iterates over successive integers:

ParallelArray[#1^#2&,{3,4}]

ParallelArray[Function[{x,y},x^y],{3,4}]

ParallelTable[x^y,{x,3},{y,4}]

(RefLink[Map, paclet:ref/Map]) applies a function to successive elements in a list:

list = RandomInteger[9,10]

ParallelMap[Last[IntegerDigits[#,2]]&, list]

(RefLink[Table, paclet:ref/Table]) can substitute successive elements in a list into an expression:

ParallelTable[Last[IntegerDigits[x,2]], {x, list}]

(RefLink[ParallelTable, paclet:ref/ParallelTable]) iterating over a given list is equivalent to (RefLink[ParallelCombine, paclet:ref/ParallelCombine]):

list= RandomInteger[9,10]

ParallelTable[x^2,{x,list}]

ParallelCombine[Function[x,x^2],list]

(RefLink[ParallelTable, paclet:ref/ParallelTable]) can be implemented with (RefLink[WaitAll, paclet:ref/WaitAll]) and (RefLink[ParallelSubmit, paclet:ref/ParallelSubmit]):

WaitAll[Table[ParallelSubmit[{i},Labeled[Framed[f[i]],$KernelID]],{i,4}]]

Parallelization at the innermost level of a multidimensional table:

WaitAll[Table[ParallelSubmit[{i,j},Labeled[Framed[f[i,j]],$KernelID]],{i,4},{j,i}]]

Functions defined interactively are automatically distributed to all kernels when needed:

ftest[n_]:=Labeled[Framed[PrimeQ[2^n-1]],$KernelID]

ParallelTable[ftest[i],{i,1275,1285}]

Distribute definitions manually and disable automatic distribution:

gtest[n_]:=Labeled[Framed[PrimeQ[2^n-1]],$KernelID]

DistributeDefinitions[gtest];

ParallelTable[gtest[i],{i,1275,1285},DistributedContexts->None]

For functions from a package, use (RefLink[ParallelNeeds, paclet:ref/ParallelNeeds]) rather than (RefLink[DistributeDefinitions, paclet:ref/DistributeDefinitions]):

Needs["FiniteFields`"]

Table[FieldSize[GF[2,i]],{i,10}]

ParallelNeeds["FiniteFields`"]

ParallelTable[FieldSize[GF[2,i]],{i,10}]

OpenersExampleSection6(Spacer1)Possible Issues  (3)

A function used that is not known on the parallel kernels may lead to sequential evaluation:

ftest[n_]:=Labeled[Framed[PrimeQ[2^n-1]],$KernelID]

ParallelTable[ftest[i],{i,1275,1285},DistributedContexts->None]

Define the function on all parallel kernels:

DistributeDefinitions[ftest]

The function is now evaluated on the parallel kernels:

ParallelTable[ftest[i],{i,1275,1285},DistributedContexts->None]

Definitions of functions in the current context are distributed automatically:

gtest[n_]:=Labeled[Framed[PrimeQ[2^n-1]],$KernelID]

ParallelTable[gtest[i],{i,1275,1285}]

Definitions from contexts other than the default context are not distributed automatically:

ctx`mtest[n_]:=Labeled[Framed[PrimeQ[2^n-1]],$KernelID]

ParallelTable[ctx`mtest[i],{i,1275,1285}]

Use (RefLink[DistributeDefinitions, paclet:ref/DistributeDefinitions]) to distribute such definitions:

DistributeDefinitions[ctx`mtest];

ParallelTable[ctx`mtest[i],{i,1275,1285}]

Alternatively, set the (RefLink[DistributedContexts, paclet:ref/DistributedContexts]) option to include all contexts:

cty`mtest[n_]:=Labeled[Framed[PrimeQ[2^n-1]],$KernelID]

ParallelTable[cty`mtest[i],{i,1275,1285},DistributedContexts->Automatic]

Trivial operations may take longer when parallelized:

AbsoluteTiming[ParallelTable[N[Sin[x]],{x,0,1000}];]

AbsoluteTiming[Table[N[Sin[x]],{x,0,1000}];]

OpenersExampleSection7(Spacer1)Neat Examples  (2)

Visualize the Mandelbrot set:

mlength[z_]:=Length[FixedPointList[#^2+z&,z,20,SameTest->(Abs[#]>2&)]]

points=ParallelTable[mlength[x+I y],{y,-1,1,0.005},{x,-2,1,0.005}];

ArrayPlot[points,ColorFunction->Hue,PixelConstrained->True]

Calculate and display the Feigenbaum (or bifurcation) diagram of the logistics map:

line[r_,dy_,np_,n0_,n_]:=Module[{pts},
With[{logistics=Function[x,r x(1-x)]},
pts=Join@@NestList[logistics,Nest[logistics,RandomReal[{0,1},np],n0],n-1]];
Log[1.0+BinCounts[pts,{0,1,dy}]]]

With[{w=400,h=250,r0=2.95,r1=4.0},
ArrayPlot[ParallelTable[line[r,1/(w-1),w,500,50],{r,r0,r1,(r1-r0)/(h-1)}],ImageSize->{w,h},PixelConstrained->True]]

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

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Data Parallelism, paclet:guide/DataParallelism])}, {▪(RefLinkPlain[Parallel Computing, paclet:guide/ParallelComputing])}, {▪(RefLinkPlain[Raspberry Pi, paclet:guide/RaspberryPi])}, {▪(RefLinkPlain[Managing Remote and Parallel Kernels, paclet:guide/ManagingRemoteAndParallelKernels])}})}})