generates in parallel a list of length n, with elements f[i], evaluated.
generates in parallel an array of nested lists, with elements f[i1,i2,…].
generates in parallel a list using the index origins ri (default 1).
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.
Examplesopen allclose all
Basic Examples (3)
ParallelArray works like Array, but in parallel:
Use index origin 0 instead of 1:
Break the computation into the smallest possible subunits:
Break the computation into as many pieces as there are available kernels:
Break the computation into at most 2 evaluations per kernel for the entire job:
Break the computation into evaluations of at most 5 elements each:
The default option setting balances evaluation size and number of evaluations:
Calculations with vastly differing runtimes should be parallelized as finely as possible:
A large number of simple calculations should be distributed into as few batches as possible:
By default, definitions in the current context are distributed automatically:
Do not distribute any definitions of functions:
Distribute definitions for all symbols in all contexts appearing in a parallel computation:
Distribute only definitions in the given contexts:
Restore the value of the DistributedContexts option to its default:
Do not show a temporary progress report:
Use Method"FinestGrained" for the most accurate progress report:
Possible Issues (2)
A function used that is not known on the parallel kernels may lead to sequential evaluation:
Define the function on all parallel kernels:
The function is now evaluated on the parallel kernels:
Definitions of functions in the current context are distributed automatically:
Definitions from contexts other than the default context are not distributed automatically:
Use DistributeDefinitions to distribute such definitions:
Alternatively, set the DistributedContexts option to include all contexts:
Wolfram Research (2008), ParallelArray, Wolfram Language function, https://reference.wolfram.com/language/ref/ParallelArray.html (updated 2010).
Wolfram Language. 2008. "ParallelArray." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2010. https://reference.wolfram.com/language/ref/ParallelArray.html.
Wolfram Language. (2008). ParallelArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ParallelArray.html