Professional Documents
Culture Documents
Message
Message
define
MessagesForP3 == { msg \in CHAN : msg[3] = "P3" }
end define;
process P1 = "P1"
variables sumP1 = 0; iP1 = 0;
begin
P1_loop: while pc["P3"] /= "Done" do
if 2*iP1 <= N \* computation not finished
then
computeP1: sumP1 := sumP1 + 2 * iP1; \* compute one step further
incriP1: iP1 := iP1 + 1;
else
send(iP1,"P1","P3"); \* emit result
end if;
end while;
end process;
process P2 = "P2"
variables sumP2 = 0; iP2 = 0;
begin
P2_loop: while pc["P3"] /= "Done" do
if 2*iP2 + 1 <= N \* computation not finished
then
computeP2: sumP2 := sumP2 + 2*iP2 + 1; \* compute one step further
incriP2: iP2 := iP2 + 1;
else
send(iP2,"P2","P3"); \* emit result
end if;
end while;
end process;
process P3 = "P3"
variables sumP3 = 0; resultP1 = UNDEF; resultP2 = UNDEF;
begin
P3_loop: while (resultP1 = UNDEF \/ resultP2 = UNDEF) do
with message \in MessagesForP3 do \* receive a message and read result
if message[2] = "P1" then
resultP1 := message[1];
elsif message[2] = "P2" then
resultP2 := message[1];
else
assert FALSE;
end if;
end with;
end while;
P3_finish: sumP3 := resultP1 + resultP2; print(sumP3); \* Compute sum and print
it
end process;
end algorithm; *)
(* define statement *)
MessagesForP3 == { msg \in CHAN : msg[3] = "P3" }
vars == << CHAN, pc, sumP1, iP1, sumP2, iP2, sumP3, resultP1, resultP2 >>
P3 == P3_loop \/ P3_finish
Next == P1 \/ P2 \/ P3
\/ Terminating
\* END TRANSLATION
====