wait for parallel computation to finish
The WaitForFirst command stops execution until one remote compute nodes is finished processing.
The returned result is the node number of an idle worker node.
When more than one compute node finish at the same time (or when nodes are already idle prior to calling WaitForFirst), the lowest node number is returned.
The WaitForFirst command is only available in local Grid mode.
This example shows the steps to start two jobs and wait for the first to finish
Grid:-Run⁡0,for i from 1 to 10^6 do od:,numnodes=2
Grid:-Run⁡1,for i from 1 to 10^5 do od:
If you are going to run the next example right away, you need to ensure both of the previous jobs are complete.
The following example demonstrates the implementation of a first-come-first-serve work splitting algorithm. As soon as a node is finished, it will get sent more work to do. Generally, unless f is expensive to compute, it is better to compute a range of things at a time in each node. This example computes only one item at a time. See Grid:-Seq for a similar concept.
runInParallel := proc( f, n )
local i, result, freenode;
result := Array(1..n);
for i from 1 to min(Grid:-NumNodes(),n) do
for i to n do
freenode := Grid:-WaitForFirst();
This example will run four different jobs and wait for the first one to finish; then will terminate the others. Note the use of Grid:-Set to define the delay procedure on the remote nodes. Make sure you reset the number of nodes before calling Set, otherwise only the active nodes will receive the definition of the delay procedure.
delay := proc( n, c )
for i from 1 to n do
The Grid[WaitForFirst] command was introduced in Maple 2015.
For more information on Maple 2015 changes, see Updates in Maple 2015.
Download Help Document
What kind of issue would you like to report? (Optional)