run a parallel computation
can either be a string containing the Maple code to run on each node, or a procedure or procedure name
list; arguments passed to the remote procedure call
integer, integer..integer, set(integer); identifier indicating which node(s) to run the command on
(optional) equation(s) of the form option=value; see the Options section below
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.
The options argument can contain one or more of the following options.
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.
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.
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.
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.
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.
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.
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.
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)
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.
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.
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 )
for i from 1 to n do
n ≔ Grid:-WaitForFirst⁡
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.
x ≔ x_local
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",
trunc(10^6*(t - trunc(t))),
node=-1 current-time=11:26:40.626143: initialize
node=0 current-time=11:26:40.691038: worker
node=2 current-time=11:26:40.698353: worker
node=1 current-time=11:26:40.697357: worker
node=3 current-time=11:26:40.699002: worker
node=-1 current-time=11:26:40.710445: done
The Grid[Run] command was introduced in Maple 2015.
For more information on Maple 2015 changes, see Updates in Maple 2015.
Download Help Document