Grid - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Toolboxes : Grid Computing : Grid/WaitForFirst

Grid

  

WaitForFirst

  

wait for parallel computation to finish

 

Calling Sequence

Description

Examples

Compatibility

Calling Sequence

WaitForFirst()

Description

• 

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.

Examples

This example shows the steps to start two jobs and wait for the first to finish

Grid:-Run0,for i from 1 to 10^6 do od:,numnodes=2

Grid:-Run1,for i from 1 to 10^5 do od:

Grid:-WaitForFirst

1

(1)

If you are going to run the next example right away, you need to ensure both of the previous jobs are complete.

Grid:-Wait

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
      Grid:-Run(i-1,f,[i],assignto='result'[i]);
  end do;
  for i to n do
      freenode := Grid:-WaitForFirst();
      Grid:-Run(freenode,f,[i],assignto='result'[i]);
  end do;
  Grid:-Wait();
  return result;
end:

runInParallelithprime,7

2357111317

(2)

runInParallelixi,5

xx2x3x4x5

(3)

runInParallelicombinat:−unrankpermi,4,combinat:-numbperm4

1,2,3,41,2,4,31,3,2,41,3,4,21,4,2,31,4,3,22,1,3,42,1,4,32,3,1,42,3,4,12,4,1,32,4,3,13,1,2,43,1,4,23,2,1,43,2,4,13,4,1,23,4,2,14,1,2,34,1,3,24,2,1,34,2,3,14,3,1,24,3,2,1

(4)

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 )
  local i;
  for i from 1 to n do
      printf("%c",c);
      Threads:-Sleep(1);
  od;
  printf("\n");
  c;
end proc:

Grid:-Setupnumnodes=4

4,3,1,2

(5)

Grid:-Setdelay

Grid:-Run0,delay,15,x

Grid:-Run1,delay,3,+

Grid:-Run2,delay,16,!

Grid:-Run3,delay,9,z

nGrid:-WaitForFirst

n0

(6)

Grid:-Interrupt

Grid:-Wait

Grid:-GetLastResultn

Compatibility

• 

The Grid[WaitForFirst] command was introduced in Maple 2015.

• 

For more information on Maple 2015 changes, see Updates in Maple 2015.

See Also

Grid

Grid:-Run

Grid:-Seq

Grid:-Wait