Send - Maple Help

Grid

 Send
 send a message from one node to another

 Calling Sequence Send( node, msg )

Parameters

 node - integer, identifying the node to send the message to msg - arbitrary Maple expression, message to send

Description

 • The Send command is for use within the Maple code executed as part of a parallel computation.
 • When a parallel job is started on a specified number of servers, say N, each server will be given an integer identifier between 0 and N-1 for the duration of this computation. The node parameter specifies the integer identifier of the node to send a message to.
 • The msg parameter can be an arbitrary Maple expression including NULL and expression sequences.  Nested structures that contain expressions with last name evaluation rules, like modules, will not send the fully evaluated sub-expression.
 • The receive buffer of an Grid server is only limited by available memory, which means that the Send command will only block for the duration of transferring the data over the network.
 • The Send command will return before the message was accepted using a Receive command on the destination node.  The return value is always NULL.
 • Note that you can create deadlock situations when all nodes are either done with their computation or still waiting to receive a message. Such deadlocks will be detected and the job will be automatically aborted.

Examples

In this example node 0 passes a message along to node 1, who adds to the message and sends it to node 2, etc.  When all nodes have seen the message, the final result is sent back to node 0.

 > circ := proc()    uses Grid;    local r, me := MyNode(), n := NumNodes();    if me = 0 then        Send(1,0);        r := Receive(n-1);      else        r := Receive(me-1);        Send(me+1 mod n, r, me);    end if; end;
 ${\mathrm{circ}}{≔}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{,}{\mathrm{me}}{,}{n}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{me}}{≔}{\mathrm{Grid}}{:-}{\mathrm{MyNode}}{}\left({}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{n}{≔}{\mathrm{Grid}}{:-}{\mathrm{NumNodes}}{}\left({}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{me}}{=}{0}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{then}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Send}}{}\left({1}{,}{0}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{≔}{\mathrm{Grid}}{:-}{\mathrm{Receive}}{}\left({n}{-}{1}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{r}{≔}{\mathrm{Grid}}{:-}{\mathrm{Receive}}{}\left({\mathrm{me}}{-}{1}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Send}}{}\left({\mathrm{me}}{+}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{n}{,}{r}{,}{\mathrm{me}}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > $\left[\mathrm{Grid}:-\mathrm{Launch}\left(\mathrm{circ},\mathrm{numnodes}=4\right)\right]$
 $\left[{0}{,}{1}{,}{2}{,}{3}\right]$ (2)

Compatibility

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