一、一般情况
1、节点P的近邻有入近邻(in-neighbor,进程只能向p发送消息)和出近邻(out-neighbor,p只能向进程发送消息)。
p的入近邻存储在集Inp中,p的出近邻邦存储在集Outp中。
2、在相位算法中,每个进程向每个出近邻只发送D条消息。仅当收到来自每个入近邻的i条消息后,才将第(i+1)条消息发送给每个出近邻。
3、通过每条信道至多发送D条消息,使消息复杂度为|E|*D。
4、算法:
cons D:integer =the network diameter;
var Recp[q] :0...D init 0.for each q∈Inp;
Sentp :0...D init 0;
begin if p is initiator then
begin forall r∈Outp do sen <tok> to r;
Sentp:=Sentp+1
end;
while minqRecp[q]<D do
begin receive <tok> (from neighbor q0);
Recp[q0]:=Recp[q0]+1;
if minqRecp[q]:=Recp[q0]+1;
begin forall rOutp do send <tok> to r;
Sentp:=Sentp+1
end
end;
decide
end
二、团网中的相位算法
如果网络是直径为1的团。在这种情况下,只接收每个近邻的一条消息,每个进程只需计算它所接收消息的总数就足够了。
var Recp:0..N-1 init 0;
Sentp:0...1 init 0;
begin if p isinitiator then
begin forall rNeighp do send <tok> to r;
Sentp:=Sentp+1
end;
while Recp<#Neighp do
begin receive <tok>;
Recp:=Recp+1;
if Sentp=0 then
begin forall r∈Neighp do send <tok> to r;
Sentp:=Sentp+1
end
end;
decide
end