Set - Maple Help

Grid

 Set
 set a variable in a remote parallel compute node

 Calling Sequence Set(v1, v2, ...) Set(node,v1, v2, ...)

Parameters

 v1 - can either be a variable name or equation of the form name=value node - integer

Description

 • The Set command sets variables in remote parallel compute nodes.
 • The Grid package provides routines for multiprocess parallelism. Each compute node runs a separate Maple process that does not share state with the main interactive Maple session. That means that a variable assigned in the main interactive session, say, a:=1 will not be automatically propagated to the remote compute nodes. The Set command provides a way to assign variables copying state from the current session to the remote session.
 • Calling Set(0,'a'=42) will assign the variable a the value 42 on node 0.  If a is already assigned 42 in the local session, this command can be shortened to Set(0,'a'). Leaving the node number off, Set('a') will cause the same value of a to be assigned on all compute nodes.
 • The Set command is only available in local Grid mode.

Examples

This example uses the anames command to list all active variables.  Note that until Grid:-Set is run, the compute nodes don't know about the variable f.

 > $f≔x↦{x}^{2}$
 ${f}{≔}{x}{↦}{{x}}^{{2}}$ (1)
 > $\mathrm{anames}\left('\mathrm{user}'\right)$
 ${\mathrm{defaultScreenWidth}}{,}{f}$ (2)
 > $\mathrm{Grid}:-\mathrm{Run}\left(\mathrm{anames},\left['\mathrm{user}'\right]\right)$
 $\left[\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}\left(\right){,}{\text{⋯ 0 .. 63 Array}}\right]$ (3)
 > $\mathrm{Grid}:-\mathrm{Set}\left('f'\right)$
 > $\mathrm{Grid}:-\mathrm{Run}\left(\mathrm{anames},\left['\mathrm{user}'\right]\right)$
 $\left[{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{f}{,}{\text{⋯ 0 .. 63 Array}}\right]$ (4)

This example shows results from multi-node computations are returned in an array

 > $\mathrm{Grid}:-\mathrm{Set}\left(0,'r'=1..5\right)$
 > $\mathrm{Grid}:-\mathrm{Set}\left(1,'r'=6..10\right)$
 > $\mathrm{Grid}:-\mathrm{Run}\left(0..1,\mathrm{add},\left['i','i'='r'\right]\right)$
 $\left[{15}{,}{40}{,}{\text{⋯ 0 .. 1 Array}}\right]$ (5)

After setting variables, it can be useful to run a quick job that prints their value

 > $\mathrm{Grid}:-\mathrm{Run}\left(0,\mathrm{print},\left['r'\right],'\mathrm{wait}'\right)$
 1 .. 5
 > $\mathrm{Grid}:-\mathrm{Run}\left(1,\mathrm{print},\left['r'\right],'\mathrm{wait}'\right)$
 6 .. 10

Variables that are local in the current scope will be global in the remote node.

 > p := proc()   local loc;   Grid:-Set(1,loc=4);   Grid:-Run(1,print,["the local variable",loc],'wait');   Grid:-Run(1,print,["the global variable",:-loc],'wait'); end;
 ${p}{≔}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{loc}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Set}}{}\left({1}{,}{\mathrm{loc}}{=}{4}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Run}}{}\left({1}{,}{\mathrm{print}}{,}\left[{"the local variable"}{,}{\mathrm{loc}}\right]{,}{'}{\mathrm{wait}}{'}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Run}}{}\left({1}{,}{\mathrm{print}}{,}\left[{"the global variable"}{,}{}{:-}{\mathrm{loc}}\right]{,}{'}{\mathrm{wait}}{'}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (6)
 > $p\left(\right)$
 "the local variable", 4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "the global variable", loc

A common way to unassign variables is to use the syntax var = 'var'. Because there are two evaluations happening (once in the call to Set, and once on the remote node), two uneval quotes are needed:

 > $\mathrm{Grid}:-\mathrm{Set}\left(1,v=4\right)$
 > $\mathrm{Grid}:-\mathrm{Run}\left(1,\mathrm{print},\left['v'\right],'\mathrm{wait}'\right)$
 4
 > $\mathrm{Grid}:-\mathrm{Set}\left(1,v=''v''\right)$
 > $\mathrm{Grid}:-\mathrm{Run}\left(1,\mathrm{print},\left['v'\right],'\mathrm{wait}'\right)$
 v

Compatibility

 • The Grid[Set] command was introduced in Maple 2015.