ParallelArray[f,n]
generates in parallel a list of length n, with elements f[i], evaluated.
ParallelArray[f,{n1,n2,…}]
generates in parallel an
array of nested lists, with elements f[i1,i2,…].
ParallelArray[f,{n1,n2,…},{r1,r2,…}]
generates in parallel a list using the index origins ri (default 1).
ParallelArray[f,dims,origin,h]
uses head h, rather than List, for each level of the array.
ParallelArray
ParallelArray[f,n]
generates in parallel a list of length n, with elements f[i], evaluated.
ParallelArray[f,{n1,n2,…}]
generates in parallel an
array of nested lists, with elements f[i1,i2,…].
ParallelArray[f,{n1,n2,…},{r1,r2,…}]
generates in parallel a list using the index origins ri (default 1).
ParallelArray[f,dims,origin,h]
uses head h, rather than List, for each level of the array.
Details and Options
- ParallelArray is a parallel version of Array, which automatically distributes different evaluations of expr among different kernels and processors.
- ParallelArray will give the same results as Array, except for side effects during the computation.
- Parallelize[Array[f,n]] is equivalent to ParallelArray[f,n].
- If an instance of ParallelArray cannot be parallelized, it is evaluated using Array.
- The following options can be given:
-
Method Automatic granularity of parallelization DistributedContexts $DistributedContexts contexts used to distribute symbols to parallel computations ProgressReporting $ProgressReporting whether to report the progress of the computation - The Method option specifies the parallelization method to use. Possible settings include:
-
"CoarsestGrained" break the computation into as many pieces as there are available kernels "FinestGrained" break the computation into the smallest possible subunits "EvaluationsPerKernel"->e break the computation into at most e pieces per kernel "ItemsPerEvaluation"->m break the computation into evaluations of at most m subunits each Automatic compromise between overhead and load balancing - Method->"CoarsestGrained" is suitable for computations involving many subunits, all of which take the same amount of time. It minimizes overhead, but does not provide any load balancing.
- Method->"FinestGrained" is suitable for computations involving few subunits whose evaluations take different amounts of time. It leads to higher overhead, but maximizes load balancing.
- The DistributedContexts option specifies which symbols appearing in expr have their definitions automatically distributed to all available kernels before the computation.
- The default value is DistributedContexts:>$DistributedContexts with $DistributedContexts:=$Context, which distributes definitions of all symbols in the current context, but does not distribute definitions of symbols from packages.
- The ProgressReporting option specifies whether to report the progress of the parallel computation.
- The default value is ProgressReporting:>$ProgressReporting.
Examples
open all close allBasic Examples (4)
ParallelArray works like Array, but in parallel:
Array[(Pause[1];f[#])&, 4]//AbsoluteTimingParallelArray[(Pause[1];f[#])&, 4]//AbsoluteTimingParallelArray[f, {3, 2}]ParallelArray[10#1 + #2&, {3, 4}]Use index origin 0 instead of 1:
ParallelArray[f, 10, 0]Start with indices 0 and 4 instead of 1:
ParallelArray[f, {2, 3}, {0, 4}]Used h instead of List for the result expression:
ParallelArray[f, {3, 2}, 1, h]Options (13)
Method (6)
Break the computation into the smallest possible subunits:
ParallelArray[Labeled[Framed[#], $KernelID]&, 10, Method -> "FinestGrained"]Break the computation into as many pieces as there are available kernels:
ParallelArray[Labeled[Framed[#], $KernelID]&, 10, Method -> "CoarsestGrained"]Break the computation into at most 2 evaluations per kernel for the entire job:
ParallelArray[Labeled[Framed[#], $KernelID]&, 12, Method -> "EvaluationsPerKernel" -> 2]Break the computation into evaluations of at most 5 elements each:
ParallelArray[Labeled[Framed[#], $KernelID]&, 18, Method -> "ItemsPerEvaluation" -> 5]The default option setting balances evaluation size and number of evaluations:
ParallelArray[Labeled[Framed[#], $KernelID]&, 18, Method -> Automatic]Calculations with vastly differing runtimes should be parallelized as finely as possible:
ParallelArray[PrimeQ[2 ^ # - 1]&, 20, 4410, Method -> "FinestGrained"]A large number of simple calculations should be distributed into as few batches as possible:
BinCounts[ParallelArray[Mod[Floor[# * Pi], 10]&, 10000, 1, Method -> "CoarsestGrained"], {0, 10}]DistributedContexts (5)
By default, definitions in the current context are distributed automatically:
remote[x_] := Labeled[Framed[x], $KernelID]ParallelArray[remote, 4]Do not distribute any definitions of functions:
local[x_] := Labeled[Framed[x], $KernelID]ParallelArray[local, 4, DistributedContexts -> None]Distribute definitions for all symbols in all contexts appearing in a parallel computation:
a`f[x_] := Labeled[Framed[x], $KernelID]ParallelArray[a`f, 4, DistributedContexts -> Automatic]Distribute only definitions in the given contexts:
b`g[x_] := Labeled[Framed[x], $KernelID]ParallelArray[b`f, 4, DistributedContexts -> {"a`"}]Restore the value of the DistributedContexts option to its default:
SetOptions[ParallelArray, DistributedContexts :> $DistributedContexts]ProgressReporting (2)
Do not show a temporary progress report:
res = ParallelArray[PrimeQ[2 ^ # - 1]&, 10000, ProgressReporting -> False];Use Method"FinestGrained" for the most accurate progress report:
res = ParallelArray[PrimeQ[2 ^ # - 1]&, 10000,
Method -> "FinestGrained", ProgressReporting -> True];
| |
Possible Issues (2)
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]ParallelArray[ftest, 10, DistributedContexts -> None]Define the function on all parallel kernels:
DistributeDefinitions[ftest]The function is now evaluated on the parallel kernels:
ParallelArray[ftest, 10, DistributedContexts -> None]Definitions of functions in the current context are distributed automatically:
gtest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelArray[gtest, 10]Definitions from contexts other than the default context are not distributed automatically:
ctx`mtest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelArray[ctx`mtest, 10]Use DistributeDefinitions to distribute such definitions:
DistributeDefinitions[ctx`mtest];ParallelArray[ctx`mtest, 10]Alternatively, set the DistributedContexts option to include all contexts:
cty`mtest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelArray[cty`mtest, 10, DistributedContexts -> Automatic]See Also
Related Guides
History
Introduced in 2008 (7.0) | Updated in 2010 (8.0) ▪ 2021 (13.0)
Text
Wolfram Research (2008), ParallelArray, Wolfram Language function, https://reference.wolfram.com/language/ref/ParallelArray.html (updated 2021).
CMS
Wolfram Language. 2008. "ParallelArray." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/ParallelArray.html.
APA
Wolfram Language. (2008). ParallelArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ParallelArray.html
BibTeX
@misc{reference.wolfram_2026_parallelarray, author="Wolfram Research", title="{ParallelArray}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/ParallelArray.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_parallelarray, organization={Wolfram Research}, title={ParallelArray}, year={2021}, url={https://reference.wolfram.com/language/ref/ParallelArray.html}, note=[Accessed: 13-June-2026]}