launch a parallel computation - Maple Help

Online Help

All Products    Maple    MapleSim

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

Grid[Launch] - launch a parallel computation

Calling Sequence






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



arguments passed to the remote procedure call

numnodes = posint


the number of nodes to run the job on

printer = procedure


callback procedure for coordinating output from each node

checkabort = procedure


callback procedure to allow early termination

imports = {list,set}


expressions to import from the current Maple session to each of the nodes

exports = {list,set}


expressions to export from the Master node, node 0, back to the Maple session where Launch was called from

clear = truefalse


indicate whether state should be cleared between calls

allexternal = truefalse


indicate whether node0 should be external



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.


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

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



I'm node 0 of 5
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 3
I'm node 1 of 3
I'm node 2 of 3


I'm node 0 of 6
I'm node 1 of 6
I'm node 2 of 6
I'm node 3 of 6
I'm node 4 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);
     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;

primetest:=procqq1isprimeqq1end proc






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




See Also

Grid, Grid[Setup]

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam