WaitAll[expr]
waits for all concurrent evaluations represented by EvaluationObject expressions in expr to finish, then returns the resulting expression obtained.
WaitAll
WaitAll[expr]
waits for all concurrent evaluations represented by EvaluationObject expressions in expr to finish, then returns the resulting expression obtained.
Details and Options
- EvaluationObject expressions are created with ParallelSubmit.
- EvaluationObject expressions may occur anywhere inside expr.
- 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)
ParallelSubmit[1 + 2]WaitAll[%]Waiting evaluations are scheduled concurrently on any available parallel kernel:
evs = Table[ParallelSubmit[Pause[1];$KernelID], {8}];AbsoluteTiming[WaitAll[evs]]Longer computations display information about their progress:
evs = Table[ParallelSubmit[Pause[1];$KernelID], {24}];AbsoluteTiming[WaitAll[evs]]
| |
Wait for all evaluations contained in a sum:
Sum[ParallelSubmit[{i}, i!], {i, 4}]WaitAll[%]Scope (5)
ev = ParallelSubmit[$KernelID]WaitAll[ev]Wait for a number of evaluations in a list:
evs = Table[ParallelSubmit[{i}, {i, PrimeQ[2 ^ i - 1]}], {i, 2200, 2222}];WaitAll[evs]Wait for evaluations contained in an arbitrarily nested structure:
mat = Outer[Composition[ParallelSubmit, f], {a, b}, {x, y}]WaitAll[mat]Wait for evaluations contained in an arbitrary arithmetic expression:
prod = Inner[Composition[ParallelSubmit, Times], {a, b, c}, {u, v, w}, Plus]WaitAll[prod]Build an association with evaluation objects inside:
tasks = AssociationMap[ParallelSubmit[PrimeQ[2 ^ # - 1]]&, Range[6]]Evaluate all of them in parallel:
WaitAll[tasks]Options (1)
Applications (4)
Run a search for a random prime on each parallel kernel:
With[{base = 10 ^ 1000, r = 10 ^ 10}, WaitAll[Table[ParallelSubmit[
While[!PrimeQ[p = RandomInteger[{base, base + r}]], Null];p], {$KernelCount}]] - base]
| |
Watch the scheduling of the evaluations while they are running:
With[{base = 10 ^ 1000, r = 10 ^ 10}, evs = Table[ParallelSubmit[
While[!PrimeQ[p = RandomInteger[{base, base + r}]], Null];p - base], {$KernelCount}];
PrintTemporary[evs];
WaitAll[evs]]Write a command that evaluates the arguments of a list in parallel:
SetAttributes[concurrentEvaluate, HoldAll]
concurrentEvaluate[l_List] := WaitAll[ParallelSubmit /@ Unevaluated[l]]concurrentEvaluate[{$KernelID, PrimeQ[2 ^ 2203 - 1], $KernelID}]Watch the scheduling of evaluations taking vastly varying amounts of time:
factors = Table[ParallelSubmit[{i}, Plus@@FactorInteger[2 ^ i - 1][[All, 2]]], {i, 195, 170, -1}];
PrintTemporary[factors];
WaitAll[factors]Find
such that
is prime, scheduling one infinite search loop for each kernel:
n = 1;primes = {};SetSharedVariable[n, primes];
evs = Table[ParallelSubmit[While[True,
With[{n = n++}, If[PrimeQ[n! + 1], AppendTo[primes, n]]]]], {$KernelCount}]Run them until manually aborted:
PrintTemporary[Dynamic[{n, primes}]];
CheckAbort[WaitAll[evs], AbortKernels[]];
{n, primes}Properties & Relations (4)
Evaluate an expression on any parallel kernel:
WaitAll[ParallelSubmit[10!]]ParallelEvaluate does the same:
ParallelEvaluate[10!, First[Kernels[]]]The "FinestGrained" Method setting schedules each item as a single evaluation:
ParallelTable[Labeled[Framed[f[i]], $KernelID], {i, 12}, Method -> "FinestGrained"]Internally it works similarly to WaitAll[ParallelSubmit[…]]:
WaitAll[Table[ParallelSubmit[{i}, Labeled[Framed[f[i]], $KernelID]], {i, 12}]]Parallelize at the innermost level of a multidimensional table:
WaitAll[Table[ParallelSubmit[{i, j}, Labeled[Framed[f[i, j]], $KernelID]], {i, 4}, {j, i}]]Scheduled evaluations no longer needed can be aborted with AbortKernels:
evs = Composition[ParallelSubmit, FactorInteger] /@ Range[10 ^ 20 + 1, 10 ^ 20 + 6]WaitAll[Take[evs, 2]]AbortKernels[];Define a number of tasks with varying runtimes:
tasks = Table[i ^ 2, {i, 0.1, 1, 0.1}]Measure the time for parallel execution:
AbsoluteTiming[WaitAll[Composition[ParallelSubmit, Pause] /@ tasks]][[1]]Scheduling larger tasks first improves load balancing:
AbsoluteTiming[WaitAll[Composition[ParallelSubmit, Pause] /@ Reverse[tasks]]][[1]]Possible Issues (3)
Each evaluation should be waited for exactly once:
ev = ParallelSubmit[1 + 1]WaitAll[ev]The evaluation object has already been completed:
WaitAll[ev]evThere is a considerable overhead for scheduling trivial calculations:
AbsoluteTiming[WaitAll[Table[ParallelSubmit[{i}, N[Sin[i]]], {i, 1000}]];]The overhead is smaller for generating fewer, but larger, evaluation units:
AbsoluteTiming[ParallelTable[N[Sin[i]], {i, 1000}, Method -> "CoarsestGrained"];]A sequential evaluation avoids all communication overhead:
AbsoluteTiming[Table[N[Sin[i]], {i, 1000}];]Functions used inside parallel evaluations need to be distributed first:
fl[n_] := Total[FactorList[x ^ n + 1][[2 ;; , 2]]]DistributeDefinitions[fl]WaitAll[Table[ParallelSubmit[{i}, fl[i]], {i, 21, 30}]]See Also
ParallelSubmit WaitNext EvaluationObject ParallelTry SocketWaitAll TaskWait
Function Repository: EvaluationObjectState
Related Guides
History
Text
Wolfram Research (2008), WaitAll, Wolfram Language function, https://reference.wolfram.com/language/ref/WaitAll.html.
CMS
Wolfram Language. 2008. "WaitAll." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/WaitAll.html.
APA
Wolfram Language. (2008). WaitAll. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/WaitAll.html
BibTeX
@misc{reference.wolfram_2026_waitall, author="Wolfram Research", title="{WaitAll}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/WaitAll.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_waitall, organization={Wolfram Research}, title={WaitAll}, year={2008}, url={https://reference.wolfram.com/language/ref/WaitAll.html}, note=[Accessed: 13-June-2026]}