360 likes | 615 Views
Distributed Algorithms. Broadcast and spanning tree. Model. Node Information: Adjacent links Neighboring nodes. Unique identity. Graph model: undirected graph. Nodes V Edges E Diameter D. Model Definition. Synchronous Model: There is a global clock.
E N D
Distributed Algorithms Broadcast and spanning tree
Model • Node Information: • Adjacent links • Neighboring nodes. • Unique identity. • Graph model: undirected graph. • Nodes V • Edges E • Diameter D
Model Definition • Synchronous Model: • There is a global clock. • Packet can be sent only at clock ticks. • Packet sent at time t is received by t+1. • Asynchronous model: • Packet sent is eventually received.
Complexity Measures • Message complexity: • Number of messages sent (worst case). • Usually assume “small messages”. • Time complexity • Synchronous Model: number of clock ticks • Asynchronous Model: • Assign delay to each message in (0,1]. • Worse case over possible delays
Problems • Broadcast - Single initiator: • The initiator has an information. • At the end of the protocol all nodes receive the information • Example : Topology update. • Spanning Tree: • Single/Many initiators. • On termination there is a spanning tree. • BFS tree: • A minimum distance tree with respect to the originator.
Basic Flooding: Algorithm • Initiator: • Initially send a packet p(info) to all neighbors. • Every node: • When receiving a packet p(info): • Sends a packet p(info) to all neighbors.
Basic Flooding: Correctness • Correctness Proof: • By induction on the distance d from initiator. • Basis d=0 trivial. • Induction step: • Consider a node v at distance d. • Its neighbor u of distance d-1 received the info. • Therefore u sends a packet p(info) to all neighbors (including v). • Eventually v receives p(info).
Basic Flooding: Complexity • Time Complexity • Synchronous (and asynchronous): • Node at distance d receives the info by time d. • Message complexity: • There is no termination! • Message complexity is unbounded! • How can we correct this?
Basic Flooding: Improved • Each node v has a bit sent[v], initially sent[v]=FALSE. • Initiator: • Initially: Send packet p(info) to all neighbors and set sent[initiator]=TRUE. • Every node v: • When receiving a packet p(info) from u: • IF sent[v]=FALSE THEN Send packet p(info) to all neighbors.
Basic Flooding: Improved • Message Complexity: • Each node sends once on each edge! • Number of messages equals to 2|E|. • Time complexity: • Diameter D. • Drawbacks • Termination detection
Spanning tree • Goal: • At the end of the protocol have a spanning tree • Motivation for building spanning tree: • Construction costs O(|E|). • Broadcast on tree: only |V|-1 messages.
Spanning tree: Algorithm • Data Structure: • Add to each node v a variable father[v]. • Initially: father[v] = null. • Each node v: • When receiving packet p(info) from u and father[v]= null • THEN Set father [v]=u.
Spanning tree Algorithm: Correctness • Correctness Proof: • Every node v (except the initiator) sets father[v]. • There are no cycles. • Is it a shortest path tree? • Synchronous • Asynchronous
Flood with Termination • Motivation: Inform Initiator of termination. • Initiator: • Initially: Send packet p(info) to all neighbors and set set[initiator]=True • Non-Initiator node w: • When receiving a packet p(info) from u: • IF sent[w]=FALSE • THEN father[w]=u; send packet p(info) to all neighbors (except u). • ELSE Send Ackto u. • After receiving Ack from all neighbors except father[w]: • Send Ack to father[w].
Flood with Termination: Correctness • Tree Construction: Proof as before. • Termination: • By induction on the distance from the leaves of the tree. • Basisd=0 (v is a leaf). • Receives immediately Ack on all packets (except father[v]). • Sends Ack packet to father[v]. • Induction step: • All nodes at distance d-1 received and sent Ack. • Nodes at distance d will eventually receive Ack, • and eventually will send Ack.
DFS Tree • Data Structure in node v: • Edge-status[v,u] for each neighbor u. • Possible values are {NEW,SENT, Done}. • Initially status[v,u]=NEW. • Node-status[v]. • Possible Values {New, Visited, Terminated} • Initially: Node-Status[v]=NEW (except the Initiator which have Node-Status[initiator]=Visited). • Parent[v]: Initially Parent[v]=Null • Packets type: • Token : traversing edges.
DFS: Algorithm • Token arrives at a node v from u: • Node_Status[v]=Visited & Edge_Status[v,u]=NEW • Edge_Status[v,u]=Done; Send token to u. • Node_Status[v]=Visited & Edge_Status[v,u]=Sent • Edge_Status[v,u]=Done. • (*) IF for some w: Edge_Status[v,w]=New THEN • Edge_Status[v,w]=Sent; Send token to w. • ELSE Node_Status=Terminated; send token to parent[v]. • [If v is the initiator then DFS terminates] • Node_Status[v]=New • Parent[v]=u; Node_Status[v]=Visited; Edge_Status[u,v]=Sent • [Same as Node_Status[v]=Visited from (*)]
DFS Tree: Performance • Correctness: • There is only one packet in transit at any time. • On each edge one packet is sent in each direction. • The parent relationship creates a DFS tree. • Complexity: • Messages: 2|E| • Time: 2|E| • How can we improve the time to O(|V|).
Spanning Tree: BFS • Synchronous model: have seen. • Asynchronous model: • Distributed Bellman-Ford • Distributed Dijkstra
BFS: Bellman-Ford • Data structure: • Each node v has a variable level[v]. • Initially level[initiator]=0 at the initiator and level[v]= at any other node v. • Variable parent, initialized at every node v to parent[v] = null. • Packet types: • layer(d) : there is a path of length at most d to the initiator.
BFS: Bellman-Ford Algorithm • Initiator: • Send packet layer(0) to all neighbors. • Every node v: • When receiving packet layer(d) from w • IF d+1 < level[v] THEN • Parent[v]=w • Level[v]=d+1 • Send layer(d+1) to all neighbors (except w).
BFS: Bellman-Ford Correctness • Correctness Proof: • Termination: Each node u updates level[u] at most |V| times. • Relationship parent creates a tree • After termination: if parent[u]=w then level[u]=level[w]+1[BSF Tree] • Complexity • Time: O(Diameter) • Messages: O(Diameter*|E|)
Bellman Ford: Multiple initiators • Set distance (id-initiator,d). • Use Lexicographic ordering. • Each node can change level at most • Number of initiators * |V| • At most |V|2
BSF: Dijkstra Illustrated k+1 1 k
BFS: Dijkstra • Asynchronous model: • Advance one level at a time. • Go back to root after adding each level. • Time = O( D2 ) • Messages = O( |E| + D * |V| ) • D=Diameter
BFS: Dijkstra • Data Structures: • Father[v]:the identity of the father of v. • Child[v,u]:u is a child of v in the tree. • Up[v,u]:u is closer to the initiator than v. • Packets • Pulse • forward • Father • Ack.
BFS: Dijkstra • In phase k: • Initiator sends a packet Pulse to its children. • Every node of the tree that receives a packet Pulse sends a packet Pulse to its children. • Every leaf v of the tree: • Sends a packet forward to all neighbors w s.t. up[v,w]=FALSE. • When receiving packet father[u] from u set child[v,u]=TRUE. • When receiving either Ack or father[w] from all neighbors w with up[v,w]=FALSE: send Ack to father[v]. • Every internal node v that receives Ack from all its children send Ack to its father father[v].
BFS: Dijkstra • A node u that receives a forward packet (from v): • First forward packet: • Sets father[u]=v • Sends father[u] to node v. • second (or more) forward packet: • Send Ack to v.
BFS: Dijkstra • End of phase k: • Initiator receives Ack from all its children. • Initiator start phase k+1. • Termination: • If no new node is reached in last phase.
BFS: Dijkstra • Correctness: • Induction on the phases • Asynchronous model. • Time = O( D2 ) • Messages = O( |E| + D * |V| ) • D=Diameter
Conclusion • Broadcast: • Flooding • Flooding with termination • Spanning tree • Unstructured spanning tree (using flooding) • DFS Tree • BFS Tree