Presentation is loading. Please wait.

Presentation is loading. Please wait.

2016/7/2Appendices A and B1 Introduction to Distributed Algorithm Appendix A: Pseudocode Conventions Appendix B: Graphs and Networks Teacher: Chun-Yuan.

Similar presentations


Presentation on theme: "2016/7/2Appendices A and B1 Introduction to Distributed Algorithm Appendix A: Pseudocode Conventions Appendix B: Graphs and Networks Teacher: Chun-Yuan."— Presentation transcript:

1 2016/7/2Appendices A and B1 Introduction to Distributed Algorithm Appendix A: Pseudocode Conventions Appendix B: Graphs and Networks Teacher: Chun-Yuan Lin

2 2016/7/2Appendices A and B2 Appendix A: Pseudocode Conventions

3 2016/7/2Appendices A and B3 Pascal-like pseudocode The pseudocode used in this book very much resembles the language Pascal. Process names can be used as array indices, and set variables are used. The variable Neigh p is the set of processes to which p is connected (the neighbors of p). Assignment ("a :== expression"). Conditional statement (“if condition then statemenf”, with an optional “else statemenf” part). loop (“while condition do statemenf”). The forall statement has the form “forall x  X do statemenf”, where x is a formal parameter and X a set. Ex. forall q  Neigh p do R p [q]:=0. begin and end.

4 2016/7/2Appendices A and B4 Message passing(1) The operations "send" and "receive" are used to describe message passing in the pseudocode. Assume that each process must send to its neighbors its identity (process name) and its degree (number of neighbors). This message is denoted as (info, a, b ). The send operation must be given a message (its type and the value of its data fields) and a destination. To send its identity and degree to process q, process p may execute: send to q. The shorthand "shout" is used to send a message to all neighbors. shout as forall q  Neigh p do send to q.

5 2016/7/2Appendices A and B5 Message passing(2) To receive a message, its type as well as formal parameters for the data fields of the message and its sender must be specified. To receive the information regarding the identity and degree of a neighboring node, process p may execute: receive from q. A process may need to receive a message from a specific process, receive from this q 0. The communication between processes can be either asynchronous or synchronous.

6 2016/7/2Appendices A and B6 Control-oriented versus event-driven notation The control-oriented notation of an algorithm consists of a declaration of its variables and a semicolon-separated list of statements enclosed between begin and end. Event-driven notation consists of a declaration of variables together with the initialization of these variables, followed by a list of actions.

7 2016/7/2Appendices A and B7

8 2016/7/2Appendices A and B8 Appendix B: Graphs and Networks

9 2016/7/2Appendices A and B9 Definitions and Terminology(1) As the topology of a distributed system is usually modeled by a graph, some knowledge of graph theory and its terminology is useful in the study of distributed algorithms. A graph can be thought of as a collection of points (called the nodes of the graph) some of which are connected by lines (the edges).

10 2016/7/2Appendices A and B10 Undirected Graphs(1) An undirected graph G is a pair (V, E), where V is a set called the node set of G and E is a collection of unordered pairs from V. An element of E is a pair of {u, v} with u, v  V. To shorten the notation, we write uv  E instead of {u, v}  E. (uv  E is equivalent to vu  E) The edge uv is called an incident edge of u (and of v). If uv  E, the nodes u and v are said to be adjacent, or neighbors. The degree of a node is the number of edges incident to it, or, equivalently, its number of neighbors. The graph is called regular if all nodes have the same degree.

11 2016/7/2Appendices A and B11 Undirected Graphs(2) A path of length k between v 0 and v k is a sequence P = of nodes such that for each i < k, v i v i+1  E. A cycle is a path of which the begin node equals the end node. A path is called simple if the nodes v 0 through v k are all different. A cycle is called simple if the nodes v 0 through v k are all different. The distance between u and v, denoted d(u, v), is the length of a shortest path between u and v. The diameter of G is the largest distance between any two nodes. An undirected graph is connected if there exists a path between each pair of nodes. An undirected graph is called acyclic if it contains no simple cycle of length three or more.

12 2016/7/2Appendices A and B12 Undirected Graphs(3) A graph G ’ = (V ’, E ’ ) is called a subgraph of G if V ’  V and E ’  E. G ’ is called a spanning subgraph if V ’ =V. G ’ is called an induced subgraph if E ’ = {uv  E| u  V ’ ^ v  V ’ }. A connected component of G is a maximal connected induced subgraph G ’ of G; that is, G ’ is a connected induced subgraph. A graph is called a planar graph if it is possible to draw the graph in the plane without crossing edges. A graph is called outerplanar if it is possible to draw the graph in the plane without crossing the edges and with all nodes on the border of the picture.

13 2016/7/2Appendices A and B13 Undirected Graphs(4) The following properties of planar and outerplanar graphs are of interest.

14 2016/7/2Appendices A and B14 Directed Graphs(1) A directed graph G is a pair (V, E), where V is the node set, and E is a collection of ordered pairs from V. uv  E is not equivalent to vu  E. The edge uv is called an outgoing edge of u and an incoming edge of v. If uv  E, v is called an out-neighbor of u, and u is called an in-neighbor of v. The in-degree of a node is the number of its incoming edges, and the out- degree is the number of outgoing edges. The degree is the sum of the in- degree and the out-degree. With same definitions for path, cycle, simple, distance by undirected graph.

15 2016/7/2Appendices A and B15 Directed Graphs(2) A directed graph is strongly connected if there exists a path from each node to each other node. A directed graph is called acyclic if it contains no simple cycle of length two or more.

16 2016/7/2Appendices A and B16 Weighted Graphs A (directed or undirected) graph is weighted if for each pair u, v with uv  E, a numerical value W uv is defined. The weight assignment is called symmetric if, for each pair, W uv = W vu. In a weighted graph, the weight of a path is defined as the sum of the edge weights over the edges in the path. If no weight assignment is assumed for a graph, it is called unweighted.

17 2016/7/2Appendices A and B17 Frequently Used Graphs Some classes of graph that occur frequently in the study of distributed algorithms, namely, rings, trees, forests, grids, tori, cliques, and hypercubes. In the sequel, G = (V, E) be a graph, N the number of its nodes, and D the diameter.

18 2016/7/2Appendices A and B18 Rings The ring topology is a circular arrangement of nodes, and is often used as a control topology in distributed computations. Definition B.l A ring is an undirected, connected, regular graph of degree two. Theorem B.2 The following are equivalent for an undirected graph G. A spanning ring can sometimes be defined in a graph G = (V, E); that is, a set E ’  E is selected such that (V, E ’ ) is a ring. It is NP-complete to decide whether a given graph has spanning ring. (not every graph contains one) (virtual ring)

19 2016/7/2Appendices A and B19 Trees, Forests, and Stars (1) Trees A tree is a graph that contains a minimal number of edges connecting its nodes, and as a result computations on tree-shaped networks may have a very low communication complexity. Definition B.3 A tree is an undirected, connected, acyclic graph. Theorem B.4 The following are equivalent for an undirected graph G.

20 2016/7/2Appendices A and B20 Trees, Forests, and Stars (2) A tree T = (V, E) is rooted if there is a unique designated node r called the root. u is a node on the (unique) simple path between v and r, u is called an ancestor of v, and v is called a descendant of u. u and v are neighbors, v is called a son (or child) of u, and u is called the father (or parent) of v. The subgraph induced by the descendants of u is a rooted tree (with root u), called the subtree of u. The depth of the tree is the maximal length of any simple path from the root to a node. Every connected graph G = (V, E) contains a spanning tree; that is, a set E ’  E can be chosen, such that (V, E ’ ) is a tree.

21 2016/7/2Appendices A and B21 Trees, Forests, and Stars (3) Low-diameter spanning tree If the spanning tree must be chosen to minimize the total time necessary for a computation on it, it is desirable that the diameter is as small as possible. Minimal-weight spanning tree If the total communication cost for a computation in a spanning tree must be low, the subtree must be chosen so as to minimize the weight of the tree. (If all edge weights are different, the minimal-weight spanning tree is unique) Restricted-degree spanning tree If the computation overhead per node must be low, a spanning tree must be selected that has a low degree for each node. Depth-first search tree A spanning tree is a depth-first search spanning tree if each frond edge connects a node and a descendant of that node.

22 2016/7/2Appendices A and B22 Trees, Forests, and Stars (4) A graph consisting of a number of isolated trees is called a forest. Definition B.5 A forest is an undirected acyclic graph. Theorem B.6 The following are equivalent for an undirected graph G. A forest is rooted if a root node is designated in every tree of the forest. Every graph has a spanning forest, consisting of a spanning tree of each connected component of the graph.

23 2016/7/2Appendices A and B23 Trees, Forests, and Stars (5) A star is a graph with one special node, the center, and all other nodes are connected only to this center. Definition B.7 A star is a rooted tree of depth one. The root of the star is called the center. Theorem B.8 The following are equivalent for an undirected graph G. Stars are not usual as a physical connection topology of a distributed systems; rather, stars are the virtual topology used in computations that are controlled by a central process.

24 2016/7/2Appendices A and B24 Cliques In a clique, sometimes also called a complete graph, each pair of nodes is directly connected by an edge. Definition B.9 A clique is a graph with diameter one. Theorem B.l0 The following are equivalent for an undirected graph G. As is the case for stars, cliques are rarely used as a physical connection topology. (higher layer)

25 2016/7/2Appendices A and B25 Grids and Tori (1) In an n × n grid there are N = n 2 nodes, arranged in n rows of n nodes each. Each node is connected to the nodes above it, right and left of it, and under it. The n × n torus is similar, but in addition the leftmost and rightmost node of each row are adjacent, and the uppermost and lowermost node of each column are adjacent. The n × n grid has 2n(n -1) edges, contains nodes of degree two, three, and four, and its diameter is 2(n - 1). The n × n torus has 2n 2 edges, is regular of degree four, and its diameter is

26 2016/7/2Appendices A and B26 Grids and Tori (2)

27 2016/7/2Appendices A and B27 Hypercubes(1) Like grids and tori, hypercubes are often used in the design of multiprocessor computers. (Both diameter and degree equal logN, where N is the number of nodes) Definition B.l2 The n-dimensional hypercube is a graph on N = 2 n nodes where each node can be assigned a unique element from the set of labels {(b 0,..., b n-1 ) : b i = 0, 1} in such a way that E = {uv : the labels of u and v differ in one bit}. Theorem B.13 The following are equivalent for an undirected graph G.

28 2016/7/2Appendices A and B28 Hypercubes(2) The hypercube is regular of degree n, and has diameter n. An (n + 1 )-dimensional hypercube can be constructed by taking two n­ dimensional hypercubes and connecting corresponding nodes.

29 2016/7/2Appendices A and B29 Hypercubes(3)

30 2016/7/2Appendices A and B30 Sense of Direction (1) It was observed that the communication complexity of distributed computations is influenced by following factors Topological awareness In order to exploit the advantages of a specific topology, it is sometimes necessary that the processes "know" that they are connected in a topology of this class. Sense of direction The routing of information through a network can be done more efficiently if the edges incident to each node are labelled with the "direction" to wl1ich they lead in the network.

31 2016/7/2Appendices A and B31 Sense of Direction (2)

32 2016/7/2Appendices A and B32 Sense of Direction-Ring As the ring is regular of degree two, there are only two directions in the ring; we call them “Pred” (previous) and “Next”. Definition B.14 A labeling of the ring is an assignment at every node of different labels from the set {Prev, Next} to the edges incident to that node. A labeling S of the ring constitutes a sense of direction if for all adjacent nodes u and v, S u (v) =Prev  S v (u) = Next.

33 2016/7/2Appendices A and B33 Sense of Direction-Cliques The clique of N nodes has degree N - 1; its directions are numbered from 1 through N – 1. Definition B.15 A labeling of the clique is an assignment at every node of different labels from the set {1,..., N - 1} to the edges incident to that node. A labeling S of the clique constitutes a sense of direction if the nodes of the clique can be numbered from 0 through N - 1, in such a way that for every i and j, S i (j) = (j - i) mod N.

34 2016/7/2Appendices A and B34 Sense of Direction-Tori The four directions of the torus are called up, down, right, and left, abbreviated U, D, R, L.

35 2016/7/2Appendices A and B35 Sense of Direction-Hypercubes The n dimensions of the n-dimensional hypercube are numbered from 0 through n - 1. There is a sense of direction if all parallel edges are labeled with the same number.

36 2016/7/2Appendices A and B36 Sense of Direction (3)


Download ppt "2016/7/2Appendices A and B1 Introduction to Distributed Algorithm Appendix A: Pseudocode Conventions Appendix B: Graphs and Networks Teacher: Chun-Yuan."

Similar presentations


Ads by Google