Launch - Maple Help

Grid

 Launch
 launch a parallel computation

 Calling Sequence Launch(code) Launch(code,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) expressions 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.
 • 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;
 ${\mathrm{hello}}{≔}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{printf}}{}\left({"I\text{'}m node %d of %d\n"}{,}{\mathrm{Grid}}{:-}{\mathrm{MyNode}}{}\left({}\right){,}{\mathrm{Grid}}{:-}{\mathrm{NumNodes}}{}\left({}\right)\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Barrier}}{}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > $\mathrm{Grid}:-\mathrm{Launch}\left(\mathrm{hello},\mathrm{numnodes}=5\right)$
 I'm node 1 of 5 I'm node 2 of 5 I'm node 3 of 5 I'm node 4 of 5 I'm node 0 of 5
 > $\mathrm{Grid}:-\mathrm{Launch}\left(\mathrm{hello},\mathrm{numnodes}=3\right)$
 I'm node 0 of 3 I'm node 1 of 3 I'm node 2 of 3
 > $\mathrm{Grid}:-\mathrm{Launch}\left(\mathrm{hello},\mathrm{numnodes}=6\right)$
 I'm node 1 of 6 I'm node 2 of 6 I'm node 0 of 6 I'm node 4 of 6 I'm node 3 of 6 I'm node 5 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;
 ${\mathrm{primetest}}{≔}{\mathbf{proc}}\left({\mathrm{qq1}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{isprime}}{}\left({\mathrm{qq1}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (2)
 > $\mathrm{userData}≔\left[\mathrm{seq}\left(\mathrm{rand}\left(1001..10001\right)\left(\right),i=1..4\right)\right]$
 ${\mathrm{userData}}{≔}\left[{8927}{,}{9058}{,}{1006}{,}{4003}\right]$ (3)
 > $\mathrm{result}≔\mathrm{Grid}:-\mathrm{Launch}\left(\mathrm{primeChecker},\mathrm{numnodes}=4,\mathrm{imports}=\left['\mathrm{primetest}','\mathrm{userData}'\right],\mathrm{exports}=\left["timingData"\right]\right)$
 Value     1006 Value     9058 Value     8927 Value     4003 Sending   [(2)*(503), false] Sending   [(2)*(7)*(647), false] Sending   [(4003), true] Received     [(2)*(7)*(647), false] Received     [(2)*(503), false] Received     [(4003), true]
 ${\mathrm{result}}{≔}\left[\left[\left({79}\right){}\left({113}\right){,}{\mathrm{false}}\right]{,}\left[\left({2}\right){}\left({7}\right){}\left({647}\right){,}{\mathrm{false}}\right]{,}\left[\left({2}\right){}\left({503}\right){,}{\mathrm{false}}\right]{,}\left[\left({4003}\right){,}{\mathrm{true}}\right]\right]$ (4)
 > $\mathrm{timingData}$
 $\left[\left[{0}{,}{0}\right]{,}\left[{1}{,}{0.100}\right]{,}\left[{2}{,}{0.}\right]{,}\left[{3}{,}{0.}\right]\right]$ (5)

Compatibility

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