分布式计算-相位算法

一、一般情况

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

 

            

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值