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

Online Help

All Products    Maple    MapleSim


Grid

  

Run

  

run a parallel computation

 

Calling Sequence

Parameters

Description

Options

Examples

Compatibility

Calling Sequence

Run(f,[fargs],options)

Run(node,f,[fargs],options)

Parameters

f

-

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

fargs

-

list; arguments passed to the remote procedure call

node

-

integer, integer..integer, set(integer); identifier indicating which node(s) to run the command on

options

-

(optional) equation(s) of the form option=value; see the Options section below

Description

• 

The Run command runs a job in parallel. The job can be run on one designated node, or on all nodes at once. A node is a remote Maple process that does not share any variable or state with the current Maple process.

• 

When using the calling sequence Run(n,f,[x]), the command f(x) will be executed on node n in the background. Maple will not wait for this command to finish before proceeding to execute the next command. Therefore, calling Run(1,f,[x]); Run(2,f,[y]); will launch the job f(x), and then immediately launch f(y) without waiting for f(x) to finish. Both f(x) and f(y) will execute on different nodes at the same time. See Grid:-Wait or Grid:-WaitForFirst to see how to sync up with a job that was previously launched. The wait=true option can be used to force the current thread to block until the remote process is finished.

  

The Run command does not attempt to analyze input dependencies and push values to the remote nodes.  This includes the declaration of f itself. Unless f is a standard Maple command, or inline procedure declaration, the Grid:-Set command needs to be employed in order to define the routine on each remote node.  

• 

When using the calling sequence, Run(f,[x]), the command f(x) will be executed on all nodes. By default, Maple will wait for the nodes to finish, and return an array of results.  

• 

When using the calling sequence, Run("command"), such that the f argument is a string, the string will be parsed and evaluated in the remote node. The fargs option will not be used.

• 

A parallel job initiated by the Run command does not terminate until all nodes are finished computing.  This is different than the Grid:-Launch command, which terminates when node 0 is done.

• 

When initiating a computation without specifying the node number, n, the same code is run on multiple 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. Otherwise, the Grid:-Set command can be used to initialize the remote nodes with different data given the same variable name.

• 

The Run command is only available in local Grid mode.

Options

  

The options argument can contain one or more of the following options.

• 

assignto=name

  

This option lets you specify a variable that will be assigned to the last result upon completion of the operation.  For example, use assignto=ret to cause the variable ret to be assigned to the run result. This is a useful option for non-blocking executions. The command Grid:-GetLastResult can also be used to get the final result of a Grid computation. When multiple nodes are involved in the execution, the last result is an array, ranging from 0 to numnodes-1, with each index containing the result from each individual node.

• 

firstarrayindex=integer

  

This option lets you specify the starting index of the result array (when computing with multiple nodes). By default, the array contains entries from 0..numnodes-1, with the value computed in node i, stored in the array at index i. It may sometimes be convenient to have the result array start at 1, in which case all node results computed at node i will be stored at index i+1.  

• 

numnodes=posint

  

This option is used to specify the number of nodes to be used in the compute pool. The default value of numnodes is given by kernelopts(numcpus). Setting this option will affect future calls to Grid:-Run and Grid:-Launch because subsequent calls will use the number of active nodes left over from the previous call.

• 

printer=procedure

  

This option lets you specify a procedure for coordinating output from each node. The printer procedure 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.

• 

set={list,set}

  

This option lets you specify some named values that should be pushed from the current session to the remote nodes. For example, set=[f,g] will cause f and g to be assigned in the compute nodes that are about to run the given command. This is synonymous with imports as used in the Grid:-Launch command. Note that there is no get option, the Grid:-Get command should be used for that instead.

• 

uneval=truefalse

  

This option controls whether fargs uses normal evaluation rules or not. The default uneval=false is to use normal evaluation rules, keeping in mind that the expression is processed twice -- once in the current environment, and once in the remote environment. For example, Run(f,[k]) will produce f(k) if k is not assigned anywhere.  If k=4 in the local environment and k=5 in the remote node, then Run(f,[k]) will produce f(4) no matter what k is assigned in the remote environment.  Using uneval quotes, Run(f,['k']) will cause 1-level of evaluation in the local environment turning 'k' into k, and the result will be f(5).  To get the symbol k, two levels of quoting is needed, Run(f,[''k'']).  The option, uneval=true, causes arguments with uneval quotes to be left alone during the local processing of fargs in the call to Run.  The remote nodes then process all arguments using normal rules.

• 

wait=truefalse

  

When this option is set to true, the Run command will block until all nodes relevant to the computation are finished.  When this option is set to false, the Run command will return immediately, while the nodes continue to operate in the background.  The default is wait=false when computing on just one node (presumably you would have just computed in the main thread if you wanted to wait for the result of just one node's work).  However, when running a job on all nodes, the default is wait=true.

Examples

It is best to leave this as the default, but for consistent example output, 4 compute nodes will be used (regardless of whether you have 4 cores)

kerneloptsnumcpus=4

8

(1)

Grid:-Setupnumnodes=4

This example shows results from multi-node computations are returned in an array. When generating random numbers, use randomize() to set a random seed for the sequence of numbers to generate. Avoid this only for testing purposes when you want a repeatable sequence. Note that randomize needs to be called on all of the compute nodes, which is done here in the first statement.

Grid:-Runrandomize:

Grid:-Runrand10..100

Grid:-Runrand10..100,firstarrayindex=1

834810040

(2)

This example shows how to run two jobs in the background. The assignto option allows to capture the results into the local session. It is important to wait for the jobs to finish before using the results or starting new jobs on the same nodes.

Grid:-Run0,Optimization:-NLPSolve,sinxx,x=1..30,assignto=ans0

Grid:-Run1,Optimization:-NLPSolve,x3+2xy2y2,x=10..10,y=10..10,initialpoint=x=3,y=4,maximize,assignto=ans1

Grid:-Wait

ans0

−0.0424796169776126,x=23.5194525023235

(3)

ans1

1050.,x=10.,y=5.

(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.

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:-Setdelay:

Grid:-Run0,delay,15,0

Grid:-Run1,delay,3,1

Grid:-Run2,delay,16,2

Grid:-Run3,delay,9,3:

nGrid:-WaitForFirst

n0

(5)

Grid:-Interrupt

Grid:-Wait

Grid:-GetLastResultn

This example shows how to set state before running a computation, and notes that uneval quoting must consider both local and remote processing of arguments.

Grid:-Set0,x=x_node0

Grid:-Set1,x=x_node1

xx_local

xx_local

(6)

Grid:-Runf,x

Grid:-Runf,x

Grid:-Runf,x

Grid:-Run0,print,x,wait

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                x_node0

This example displays a message including the current clock time before, during, and after running jobs on all nodes.

show_time := proc( msg := "" )
    local t := time[current]();
    printf("node=%d current-time=%s.%d: %s\n",
       Grid:-MyNode(),
       StringTools:-FormatTime("%I:%M:%S",timestamp=trunc(t)),
          trunc(10^6*(t - trunc(t))),
       msg);
end proc:

show_timeinitialize

node=-1 current-time=12:03:25.810297: initialize

Grid:-Setshow_time

Grid:-Runshow_time,worker,wait=true

node=0 current-time=12:03:25.827183: worker
node=1 current-time=12:03:25.827655: worker
node=3 current-time=12:03:25.862110: worker
node=2 current-time=12:03:25.861783: worker

show_timedone

node=-1 current-time=12:03:25.871838: done

Compatibility

• 

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

• 

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

See Also

Grid