ParallelCombine[f,h[e1,e2,…],comb]
evaluates f[h[e1,e2,…]] in parallel by distributing parts of the computation to all parallel kernels and combining the partial results with comb.
ParallelCombine[f,h[e1,e2, …]]
is equivalent to ParallelCombine[f,h[e1,e2,…],h] if h has attribute Flat, and ParallelCombine[f,h[e1,e2,…],Join] otherwise.
ParallelCombine
ParallelCombine[f,h[e1,e2,…],comb]
evaluates f[h[e1,e2,…]] in parallel by distributing parts of the computation to all parallel kernels and combining the partial results with comb.
ParallelCombine[f,h[e1,e2, …]]
is equivalent to ParallelCombine[f,h[e1,e2,…],h] if h has attribute Flat, and ParallelCombine[f,h[e1,e2,…],Join] otherwise.
Details and Options
- ParallelCombine[f,h[e1,…,en],comb] forms expressions f[h[e1,…,ek]], f[h[ek+1,…]], …, f[h[…,en]], evaluates these on all available kernels, and combines the results ri with comb[r1,r2,…].
- The default combiner Join is appropriate for functions f such that the result of f[h[e1,…,ek]] has head h. This includes all functions with attribute Listable.
- For heads h with attribute Flat the default combiner h effectively implements the associative law h[e1,…,en] = h[h[e1,…,ek],h[ek+1,…],…,h[…,en]].
- With a compatible choice of comb, ParallelCombine[f,h[e1,e2,…],comb] is equivalent to f[h[e1,e2,…]].
- If no kernels are available, ParallelCombine evaluates f[h[e1,e2,…]] normally.
- ParallelCombine takes the same Method option as Parallelize. 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 - ParallelCombine takes the same DistributedContexts option as Parallelize; the default value is DistributedContexts:>$DistributedContexts.
- 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 (2)
Apply f in parallel to chunks of a list (with 4 parallel kernels available):
ParallelCombine[f[#]&, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, comb]Show where each computation takes place:
ParallelCombine[Composition[Labeled[#, $KernelID]&, Framed, f], {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, comb]By default Join is used as a combiner function:
ParallelCombine[# ^ 2&, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}]Do a parallel filtering operation:
ParallelCombine[Select[#, PrimeQ]&, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}]Scope (9)
Listable Functions (1)
All Listable functions can be parallelized with ParallelCombine:
ParallelCombine[Sqrt, Range[10]]ParallelCombine[Prime, Range[10]]If the function is not Listable use an explicit Map:
ParallelCombine[Map[f, #]&, {a, b, c, d, e, f}]Structure-Preserving Functions (3)
Many functional programming constructs can be parallelized with ParallelCombine:
ParallelCombine[Map[f, #]&, {a, b, c, d, e, f}]ParallelCombine[Apply[f, #, 1]&, {{a, b, c}, {u, v, w}}]The result need not have the same length as the input:
ParallelCombine[Cases[#, _ ? PrimeQ]&, Range[100]]ParallelCombine[Select[#, PrimeQ]&, Range[100]]Evaluate the elements of a list in parallel:
ParallelCombine[Identity, Unevaluated[{1 + 1, 2 + 2, 3 + 3}]]Reductions (3)
The overall count of matching elements is equal to the sum of the partial counts:
ParallelCombine[Count[#, _ ? PrimeQ]&, Range[10000], Plus]An element appears in a list if it appears in at least one of the pieces:
ParallelCombine[MemberQ[#, 5]&, Range[20], Or]An element does not appear on a list if it appears in none of the pieces:
ParallelCombine[FreeQ[#, 5]&, Range[20], And]Associative Functions (2)
Each subkernel performs a smaller number of additions and the combiner combines the results:
ParallelCombine[Identity, Unevaluated[a + b + c + d + e + f], comb]ParallelCombine[Identity, Unevaluated[a + b + c + d + e + f], Plus]Automatically pick the combiner for Flat functions:
ParallelCombine[Identity, Unevaluated[a + b + c + d + e + f]]Typical Flat functions:
ParallelCombine[Identity, Unevaluated[1 + 2 + 3 + 4 + 5 + 6]]ParallelCombine[Identity, Unevaluated[1 * 2 * 3 * 4 * 5 * 6]]ParallelCombine[Identity, Unevaluated[Max[1, 2, 3, 4, 5, 6]]]ParallelCombine[Identity, Unevaluated[Min[1, 2, 3, 4, 5, 6]]]ParallelCombine[Identity, Unevaluated[GCD[1, 2, 3, 4, 5, 6]]]ParallelCombine[Identity, Unevaluated[LCM[1, 2, 3, 4, 5, 6]]]Generalizations & Extensions (1)
Options (11)
Method (6)
Break the computation into the smallest possible subunits:
ParallelCombine[Labeled[Framed[#], $KernelID]&, Range[10], List, Method -> "FinestGrained"]Break the computation into as many pieces as there are available kernels:
ParallelCombine[Labeled[Framed[#], $KernelID]&, Range[10], List, Method -> "CoarsestGrained"]Break the computation into at most 2 evaluations per kernel for the entire job:
GatherBy[ParallelCombine[{$KernelID, #}&, Range[18], List, Method -> "EvaluationsPerKernel" -> 2], First]Break the computation into evaluations of at most 5 elements each:
ParallelCombine[{$KernelID, Length[#]}&, Range[18], List, Method -> "ItemsPerEvaluation" -> 5]The default option setting balances evaluation size and number of evaluations:
ParallelCombine[{$KernelID, Length[#]}&, Range[40], List, Method -> Automatic]Visualize the number of evaluations per kernel and items per evaluation:
Manipulate[batches = ParallelCombine[{$KernelID, Length[#]}&, Range[items], List, Method -> method];
BarChart[Map[Labeled[#, #, Center]&, Last /@ Sort[{#[[1, 1]], Last /@ #}& /@ GatherBy[batches, First]], {2}], ChartLayout -> "Stacked"],
{method, {"FinestGrained", "CoarsestGrained", Automatic}},
{items, 1, 100, 1}, SaveDefinitions -> True]DistributedContexts (5)
By default, definitions in the current context are distributed automatically:
remote[x_] := {$KernelID, Length[x]}ParallelCombine[remote, Range[39], List]Do not distribute any definitions of functions:
local[x_] := {$KernelID, Length[x]}ParallelCombine[local, Range[38], List, DistributedContexts -> None]Distribute definitions for all symbols in all contexts appearing in a parallel computation:
a`f[x_] := {$KernelID, Length[x]}ParallelCombine[a`f, Range[37], List, DistributedContexts -> Automatic]Distribute only definitions in the given contexts:
b`f[x_] := {$KernelID, Length[x]}ParallelCombine[b`f, Range[36], List, DistributedContexts -> {"a`"}]Restore the value of the DistributedContexts option to its default:
SetOptions[ParallelCombine, DistributedContexts :> $DistributedContexts]Applications (3)
Reduce an associative expression in parallel:
ParallelCombine[Identity, Unevaluated[1 + 2 + 3 + 4 + 5 + 6 + 7 + 8]]Find out how a computation is distributed among all kernels:
ParallelCombine[{$KernelID, Length[#]}&, Range[20], List]A parallel version of MapThread:
parallelMapThread[f_, args_List] := ParallelCombine[f@@@#&, Transpose[args]]parallelMapThread[f, {{a, b, c}, {u, v, w}, {x, y, z}}]Properties & Relations (5)
An implementation of ParallelMap:
ParallelCombine[Map[f, #]&, {a, b, c, d, e}]For listable functions ParallelCombine and ParallelMap are equivalent:
ParallelCombine[Sin, Range[0.0, 1, 0.1]]ParallelMap[Sin, Range[0.0, 1, 0.1]]Parallelize is often implemented in terms of ParallelCombine:
Parallelize[Count[Range[20], _ ? PrimeQ]]ParallelCombine[Count[#, _ ? PrimeQ]&, Range[20], Plus]Parallelize[Select[Range[100], PrimeQ]]ParallelCombine[Select[#, PrimeQ]&, Range[100]]Parallel versions of many data-parallel commands can easily be written with ParallelCombine:
parallelCount[range_, patt_] := ParallelCombine[Count[#, patt]&, range, Plus]parallelCount[Range[10000], _ ? PrimeQ]Functions defined interactively are automatically distributed to all kernels when needed:
ftest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]ParallelCombine[ftest /@ #&, Range[1275, 1285]]Distribute definitions manually and disable automatic distribution:
gtest[n_] := Labeled[Framed[PrimeQ[2 ^ n - 1]], $KernelID]DistributeDefinitions[gtest];The function is now evaluated on the parallel kernels:
ParallelCombine[gtest /@ #&, Range[1275, 1285], DistributedContexts -> None]Possible Issues (2)
The combiner must be compatible with the type of the partial results:
ParallelCombine[Count[#, _ ? PrimeQ]&, Range[100], Plus]The default combiner is Join, which is appropriate for list-like results:
ParallelCombine[Cases[#, _ ? PrimeQ]&, Range[100]]Functions may simplify short argument lists, but not longer ones:
{Xnor[a], Xnor[b, c], Xnor[d, e, f]}Such simplification of partial expressions may make parallel evaluation impossible:
ParallelCombine[Map[fun, #]&, Xnor[a, b, c, d, e, f], Join]Prevent simplification of partial expressions and apply the desired function only at the end:
Xnor@@ParallelCombine[Map[fun, #]&, {a, b, c, d, e, f}, Join]Related Guides
Related Workflows
- Run a Computation in Parallel
Text
Wolfram Research (2008), ParallelCombine, Wolfram Language function, https://reference.wolfram.com/language/ref/ParallelCombine.html (updated 2010).
CMS
Wolfram Language. 2008. "ParallelCombine." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2010. https://reference.wolfram.com/language/ref/ParallelCombine.html.
APA
Wolfram Language. (2008). ParallelCombine. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ParallelCombine.html
BibTeX
@misc{reference.wolfram_2026_parallelcombine, author="Wolfram Research", title="{ParallelCombine}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/ParallelCombine.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_parallelcombine, organization={Wolfram Research}, title={ParallelCombine}, year={2010}, url={https://reference.wolfram.com/language/ref/ParallelCombine.html}, note=[Accessed: 13-June-2026]}