WaitNext

WaitNext[{eid1,eid2,}]

waits until the first evaluation represented by any of the eidi finishes, then returns its result, the corresponding eidi, and the list of remaining eidk.

Details

  • The eidi are EvaluationObject expressions obtained by submitting expressions for concurrent evaluation using ParallelSubmit.
  • WaitNext[{eid1,eid2,}] returns a list {res,eid,eids}, where res is the result of the finished evaluation, eid is its EvaluationObject, and eids is the list of remaining evaluations.
  • The last element in the list produced by WaitNext is suitable for another call to WaitNext.

Examples

open allclose all

Basic Examples  (1)

Submit a number of integer factorizations:

Wait until the fastest one is done:

Wait for the next one:

Finally, wait for all remaining ones:

Applications  (1)

Test for primality, returning $Failed if it is not prime:

Adaptively schedule search jobs until a result has been found or the computation is aborted:

Properties & Relations  (2)

ParallelTry is essentially implemented in terms of WaitNext:

Scheduled evaluations no longer needed can be aborted with AbortKernels:

Possible Issues  (2)

No more than $KernelCount evaluations are initially run to find the fastest one:

Each evaluation should be waited for exactly once:

One of the evaluation objects has already completed:

Introduced in 2008
 (7.0)