Grid

 receive a message sent from another node

Parameters

 node - (optional) integer, identifying the node that the message is coming from

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 that we expect a message to arrive from.
 • The Receive command will block until a message arrives from the specified node. If no node is specified, Receive will return the first message sent to it from any node.
 • 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

 > fib := proc()     uses Grid;     local me, msg, n, dest;     me := MyNode():     n  := NumNodes():     dest := me+1 mod n:     if me=0 then         # create a message         msg := [1,1];         # send it on to node number 1         Send(dest, msg);         # wait for a message to come back         return Receive();     else         # wait for a message to arrive         msg := Receive(me-1);         # add to the sequence and send it on to the next node         Send(dest, [op(msg),msg[-1]+msg[-2]] );     end if; end proc;
 ${\mathrm{fib}}{≔}{\mathbf{proc}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{me}}{,}{\mathrm{msg}}{,}{n}{,}{\mathrm{dest}}{;}\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}}{\mathrm{dest}}{≔}{\mathrm{me}}{+}{1}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{mod}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{n}{;}\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{msg}}{≔}\left[{1}{,}{1}\right]{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Send}}{}\left({\mathrm{dest}}{,}{\mathrm{msg}}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{return}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Receive}}{}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{else}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{msg}}{≔}{\mathrm{Grid}}{:-}{\mathrm{Receive}}{}\left({\mathrm{me}}{-}{1}\right){;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{Grid}}{:-}{\mathrm{Send}}{}\left({\mathrm{dest}}{,}\left[{\mathrm{op}}{}\left({\mathrm{msg}}\right){,}{\mathrm{msg}}{[}{−}{1}{]}{+}{\mathrm{msg}}{[}{−}{2}{]}\right]\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end if}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end proc}}$ (1)
 > $\mathrm{Grid}:-\mathrm{Launch}\left(\mathrm{fib},\mathrm{numnodes}=8\right)$
 $\left[{1}{,}{1}{,}{2}{,}{3}{,}{5}{,}{8}{,}{13}{,}{21}{,}{34}\right]$ (2)

Compatibility

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