receive a message sent from another node - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Toolboxes : Grid Computing : Grid/Receive

Grid[Receive] - receive a message sent from another node

Calling Sequence






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



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.


fib := proc()
    uses Grid;
    local me, 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();
        # 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;

Warning, `msg` is implicitly declared local to procedure `fib`

fib:=proclocalme,n,dest,msg;me:=Grid:-MyNode;n:=Grid:-NumNodes;dest:=me+1modn;ifme=0thenmsg:=1,1;Grid:-Senddest,msg;returnGrid:-Receiveelsemsg:=Grid:-Receiveme1;Grid:-Senddest,opmsg,msg[−1]+msg[−2]end ifend proc





See Also

Grid, Grid[Send], Grid[Setup]

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam