>
|
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();
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;
|