Launch - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Grid

  

Launch

  

launch a parallel computation

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

Launch(code)

Launch(code,codeargs=[args],options)

Parameters

code

-

can either be a string containing the Maple code to run on each node, or a self-contained procedure

args

-

arguments passed to the remote procedure call

numnodes = posint

-

(optional) the number of nodes to run the job on

printer = procedure

-

(optional) callback procedure for coordinating output from each node

checkabort = procedure

-

(optional) callback procedure to allow early termination

imports = {list,set}

-

(optional) expressions to import from the current Maple session to each of the nodes

exports = {list,set}

-

(optional) names/strings to export from the Master node, node 0, back to the Maple session where Launch was called from

clear = truefalse

-

(optional) indicate whether state should be cleared between calls

allexternal = truefalse

-

(optional) indicate whether node 0 should be external

Description

• 

The Launch command runs a job in parallel.  The job is specified as the first argument and can either be a string containing Maple statements, or a self-contained procedure.  By self-contained, we mean a procedure that doesn't reference any other procedures or data that are not in the general memory space of remote node processes.  

  

When code is given as a procedure, additional arguments passed to Launch will be given as arguments to the procedure call.  For example, calling Launch(f,1,2,numnodes=4) will execute f(1,2) on each of the nodes.  For compatibility with previous versions of this command, callbacks and import/export definitions can also be specified as positional arguments; meaning procedure, list, and set types intended as additional arguments to the code may be misidentified as one of this other positional arguments.   Therefore it is safer to use the codeargs option to specifiy additional arguments.   The calling sequence, Launch(f,codeargs=[a,b],numnodes=4) will execute f(a,b) on the nodes rather than attempting to export variables a and b.    

• 

The same code is run on all nodes.  The MyNode command can be queried and used to take different branches within that code in order to assign alternate tasks to designated nodes within a computation.

• 

A parallel job terminates as soon as the computation on node 0 is done. Computation on all remaining nodes will be aborted at that time.

• 

Launch returns the last value computed on node 0. If code produces no last value, then the empty string, "", is returned.

• 

The Nodes attempt to detect deadlocks in the code executing in the job. If the deadlock timeout occurs, default 10 seconds, then the job is aborted. A launched job is deadlocked when all nodes are waiting for messages and no node is left computing or sending messages.

• 

The numnodes option specifies the number of processes to run the parallel job on.  In local mode, this is either the number of processors on your machine as determined by kernelopts(numcpus);, or the maximum number of nodes initialized by previous calls to Launch in the current session.  In distributed mode, numnodes defaults to the number of processes ready to compute as determined by the second result from a call to Grid[Status].

• 

The imports option specifies a list or set of variables to transfer from the current Maple session to the each node prior to execution.  The contents of the list can be one of three forms:  name = value pairs, assigned names, or strings representing global names.  

• 

The exports option specifies a list of variables to transfer from node 0 back to the current Maple session after job execution terminates successfully. The list must contain only strings representing global names. Since node 0 is the same as the current Maple session when running in local mode, this option requires no extra work.

• 

The printer option specifies a procedure that will be called with a string every time there is a line of output available from an external computation. The printf command is the default if no custom procedure is supplied.   The printer is called with a single argument, a string, that represents intermediate printed output from each of the nodes.

• 

The checkabort option specifies a procedure that will be called periodically without arguments. If the procedure returns true, the computation will be aborted on all nodes. If the procedure returns false, the computation will proceed. This option is ignored when running in local Grid mode.

• 

The clear option is only available in "local" mode. By default, clear = true, so that the state of all nodes is reset at the end of a call to Launch.  If clear = false, the state of remote nodes will not be reset when the node is finished computing.

• 

The allexternal option is only available in "local" mode. In all modes, the default action is for the process calling launch to spawn N external nodes and wait for them to finish, while in the meantime processing only displayed output.  When allexternal is set to false in "local" mode, the calling process becomes node 0. This is especially useful in situations where node 0 handles the job of passing out data and collecting results.  Since the data is already available prior to calling Launch, the need for using the imports and exports options can then be bypassed.  Note that as a side effect of running locally, assignments made during execution will persist after the job is completed, and the session state will not be cleared on node 0.   

• 

When running the Grid package in one of the distributed modes (available as a separate licensed toolbox), prior to launching a parallel job, you must be sure that servers are running on all the machines that you want to use and that you have called the Setup command to identify one of these machines as the Master Node.  The easiest way to configure and launch such a parallel computation is via the interactive worksheet page that is displayed when you call Launch() without arguments. On Windows there is also an icon created on the Desktop that is a shortcut to a Grid Computing worksheet that can serve as start page for Grid Computing tasks. Note that you can query the location of the Grid toolbox installation using the command kernelopts(toolboxdir="Grid"). The interactive Grid Computing page requires the Maple Standard Worksheet Interface.

Examples

hello := proc()
   uses Grid;
   printf("I'm node %d of %d\n",MyNode(),NumNodes());
   Barrier();
end;

helloprocprintfI'm node %d of %d\n,Grid:-MyNode,Grid:-NumNodes;Grid:-Barrierend proc

(1)

Grid:-Launchhello,numnodes=5

I'm node 1 of 5
I'm node 2 of 5
I'm node 0 of 5
I'm node 4 of 5
I'm node 3 of 5

Grid:-Launchhello,numnodes=3

I'm node 0 of 3
I'm node 2 of 3
I'm node 1 of 3

Grid:-Launchhello,numnodes=6

I'm node 0 of 6
I'm node 1 of 6
I'm node 2 of 6
I'm node 5 of 6
I'm node 4 of 6
I'm node 3 of 6

primeChecker := proc()
  uses Grid;
  local nn, thisNode, i, myVal, rslt, rply, t1, t2, b1;
  global timingData, userData, primetest;

  nn := NumNodes();
  thisNode := MyNode();
  myVal := userData[thisNode+1];
  printf("Value     %a\n", myVal);

  b1:= primetest(myVal);
  rslt := [ ifactor(myVal), b1];
  if thisNode <> 0 then
     printf("Sending   %a\n", rslt);
     Send(0, rslt);
  else
     timingData := [0, 0];
     rply := rslt;
     t1 := time[real]();
     for i from 1 to (nn-1) do
        rslt := Receive(i);
        printf("Received     %a\n", rslt);
        rply := rply, rslt;
        t2 := time[real]();
        timingData := timingData, [i, t2-t1];
        t1 := t2;
     end do;
     timingData := [timingData];
     return [rply];
  end if;
end proc:

primetest := proc(qq1) isprime(qq1) end;

primetestprocqq1isprimeqq1end proc

(2)

userDataseqrand1001..10001&comma;i=1..4

userData8927&comma;9058&comma;1006&comma;4003

(3)

resultGrid:-LaunchprimeChecker&comma;numnodes=4&comma;imports=primetest&comma;userData&comma;exports=timingData

Value     8927
Value     9058
Sending   [``(2)*``(7)*``(647), false]
Value     4003
Sending   [``(4003), true]
Value     1006
Sending   [``(2)*``(503), false]
Received     [``(2)*``(7)*``(647), false]
Received     [``(2)*``(503), false]
Received     [``(4003), true]

result79113&comma;false&comma;27647&comma;false&comma;2503&comma;false&comma;4003&comma;true

(4)

timingData

0&comma;0&comma;1&comma;0.100&comma;2&comma;0.&comma;3&comma;0.

(5)

Compatibility

• 

The Grid[Launch] command was introduced in Maple 15.

• 

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

See Also

Grid

Grid[Setup]