0% found this document useful (0 votes)
10 views38 pages

Lecture-02. Message Passing

Uploaded by

R N Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views38 pages

Lecture-02. Message Passing

Uploaded by

R N Shukla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Lecture: 02

Basic Algorithms in Message-


Passing Systems

Rajiv Misra
Dept. of Computer Science & Engineering
Indian Institute of Technology Patna
[email protected]
Preface
Recap of previous lecture:
• Distributed Algorithms assume asynchrony, local knowledge and failures.
Content of this lecture:
• This lecture introduces the formal model of a distributed message
passing system. Two main timing models, synchronous and
asynchronous are considered.
• Few simple algorithms for message-passing systems with arbitrary
topology, both synchronous and asynchronous will be discussed.
• These algorithms broadcast information, collect information, and
construct spanning trees of the network.
Message-Passing Model
• In a message-passing system, processors communicate by
sending messages over communication channels, where
each channel provides a bidirectional connection between
two specific processors.
• The pattern of connections provided by the channels
describes the topology of the system.
• The collection of channels is often referred to as the network
Message-Passing Model
• More formally, a system or algorithm consists of n
processors p0, p1, …, pn-1 ; i is the index of processor pi
(nodes of graph)
• bidirectional point-to-point channels
(undirected edges of graph)
• each processor labels its incident channels 1, 2, 3,…; might
not know who is at other end
Message-Passing Model

1 1
p3 p0

2 3

2
2
p2 p1
1 1
Modeling Processors and Channels
• Processor is a state machine including
• local state of the processor
• mechanisms for modeling channels
• Channel directed from processor pi to processor pj is modeled in two
pieces:
• outbuf variable of pi and
• inbuf variable of pj
• Outbuf corresponds to physical channel, inbuf to incoming message
queue
Modeling Processors and Channels
inbuf[1] outbuf[2]

p1's local
variables p2's local
variables

outbuf[1] inbuf[2]

Pink area (local vars + inbuf) is accessible state


for a processor.
Configuration

• Vector of processor states (including outbufs, i.e., channels),


one per processor, is a configuration of the system
• Captures current snapshot of entire system: accessible processor states
(local vars + incoming msg queues) as well as communication channels.
Events

• Occurrences that can take place in a system are modeled as events.

• For message-passing systems, we consider two kind of events:

(i) Deliver event and


(ii) Computation event
(i) Deliver Event

• Moves a message from sender's outbuf to receiver's inbuf;


message will be available next time receiver takes a step

Sender p1 m3 m2 m1 Receiver
p2

Sender p1 m3 m2 m1 p2 Receiver
(ii) Computation Event

• Occurs at one processor


• Start with old accessible state (local vars + incoming messages)
• Apply transition function of processor's state machine; handles all
incoming messages
• End with new accessible state with empty inbufs, and new
outgoing messages
There are 3 things happening in computational event:
1) Start with old accessible state
2) Apply transition function of processor's state machine;
Computation Event handles all incoming messages
3) End with new accessible state with empty inbufs, and
new outgoing messages

c old d e new
local local
state state

pink indicates accessible state: local vars and incoming msgs


white indicates outgoing msg buffers
Execution

• Format is
config, event, config, event, config, …
• in first config: each processor is in initial state and all inbufs are
empty
• for each consecutive (config, event, config), new config is same as
old config except:
• if delivery event: specified msg is transferred from sender's outbuf to
receiver's inbuf
• if computation event: specified processor's state (including outbufs)
change according to transition function
Admissibility

• Definition of execution gives some basic "syntactic" conditions.


• usually safety conditions (true in every finite prefix)

• Informally, a safety condition states that nothing bad has happened


yet; for instance, the example just given can be restarted to require
that a step by p1 never immediately follows a step by any processor
other than p0.
Admissibility
• Sometimes we want to impose additional constraints
• usually liveness conditions (eventually something happens)
• A liveness condition is a condition that must hold a certain number of times,
possible an infinite number of times
• Informally, a liveness condition states that the eventually something good
happens
• Any sequence that satisfies all required safety conditions for a particular system
type will be called an execution
• If an execution also satisfies all required liveness conditions, it will be called
admissible
• Executions satisfying the additional constraints are admissible. These are the
executions that must solve the problem of interest
Types of message-passing systems
There are two types of message-passing systems, asynchronous and synchronous.

1) Asynchronous Systems: A system is said to be asynchronous if there is no fixed


upper bound on how long it takes for a message to be delivered or how much
time elapses between consecutive steps of a processor. An example of an
asynchronous system is the Internet, where message (for instance E-mail) can
take days to arrive, although often they only take seconds.

2) Synchronous Systems: In the synchronous model processor execute in lockstep:


The execution is partitioned into rounds, and in each round, every processor can
send message to each neighbour, the messages are delivered, and every
processor computes based on the messages just received.
1. Asynchronous Message Passing Systems

• An execution is admissible for the asynchronous model if


• every message in an outbuf is eventually delivered
• every processor takes an infinite number of steps

• No constraints on when these events take place: arbitrary message


delays and relative processor speeds are not ruled out
• Models reliable system (no message is lost and no processor stops
working)
2. Synchronous Message Passing Systems

• The new definition of admissible captures lockstep unison feature of


synchronous model.
• This definition also implies
• every message sent is delivered
• every processor takes an infinite number of steps.

• Time is measured as number of rounds until termination.


Broadcast and Convergecast on a
Spanning Tree
Broadcast Over a Rooted Spanning Tree
• Broadcast is used to send the information to all.
• Suppose processors already have information about a rooted
spanning tree of the communication topology
• tree: connected graph with no cycles
• spanning tree: contains all processors
• rooted: there is a unique root node

• Implemented via parent and children local variables at each


processor
• indicate which incident channels lead to parent and children in
the rooted spanning tree
Broadcast Over a Rooted Spanning Tree: Concept

• root initially sends M to its children


• when a processor receives M from its parent
• sends M to its children
• terminates (sets a local boolean to true)
Broadcast Over a Rooted Spanning Tree: Algorithm 1
Broadcast Over a Rooted Spanning Tree: Example

Two steps in an execution of the broadcast algorithm


Complexity Analysis

• Synchronous model:
• time is depth d of the spanning tree. ( at most n – 1 when chain)
• number of messages is n - 1, since one message is sent over each
spanning tree edge
• Asynchronous model:
• same as synchronous ie time (d) and messages (n-1)
Convergecast: Concept

• Convergecast is used to collect the information.


• Again, suppose a rooted spanning tree has already been computed by
the processors
• parent and children variables at each processor

• Do the opposite of broadcast:


• leaves send messages to their parents
• non-leaves wait to get message from each child, then send combined
(aggregate) info to parent
Convergecast: Example
a

b,d c,f,h

b c

dotted lines: d e,g f,h


non-tree edges
d e f

g h
solid arrows:
g h
parent-child relationships
Convergecast: Example

Two steps in an execution of the convergecast algorithm


Finding a Spanning Tree Given a Root

• Having a spanning tree is very convenient.


• How do you get one?
• Suppose a distinguished processor is known, to serve as the root.
Finding a Spanning Tree Given a Root
• root sends M to all its neighbors
• when non-root first gets M
• set the sender as its parent
• send "parent" msg to sender
• send M to all other neighbors (if no other neighbors, then terminate)

• when get M otherwise


• send "reject" msg to sender

• use "parent" and "reject" msgs to set children variables and know when
to terminate (after hearing from all neighbors)
Execution of Spanning Tree Algorithm
root root
a a
Both models:
O(m) messages
b c O(diam) time b c

d e f d e f

g h g h

Synchronous: always gives Asynchronous: not


breadth-first search (BFS) tree necessarily BFS tree
Execution of Spanning Tree Algorithm
root a No! a root

b c b c

d e f d e f

g h g h

An asynchronous execution Another asynchronous


gave this depth-first search (DFS) execution results in this tree:
tree. Is DFS property guaranteed? neither BFS nor DFS
Finding a DFS Spanning Tree Given a Root
• when root first takes step or non-root first receives M:
• mark sender as parent (if not root)
• for each neighbor in series
• send M to it
• wait to get "parent" or "reject" msg in reply
• send "parent" msg to parent neighbor

• when processor receives M otherwise


• send "reject" to sender
• use "parent" and "reject" msgs to set children variables and know when to
terminate
Finding a DFS Spanning Tree Given a Root

• Previous algorithm ensures that the spanning tree is always a DFS tree.
• Analogous to sequential DFS algorithm.
• Message complexity: O(m) since a constant number of messages are
sent over each edge
• Time complexity: O(m) since each edge is explored in series.
Finding a Spanning Tree Without a Root

• Assume the processors have unique identifiers (otherwise impossible!)


• Idea:
• each processor starts running a copy of the DFS spanning tree
algorithm, with itself as root
• tag each message with initiator's id to differentiate
• when copies "collide", copy with larger id wins.

• Message complexity: O(nm)


• Time complexity: O(m)
Conclusion
• This lecture introduced the formal model of a distributed
message passing system i.e. synchronous and asynchronous
• Few algorithms of message-passing systems are demonstrated to
understand their concepts and complexity measures.
• The algorithms solve the problems of broadcast, convergecast,
DFS. These are used as a basic building blocks of distributed
algorithm.
• In upcoming lectures, we will try to give a more detailed
discussion on Leader Election and Minimum Cost Spanning Tree.

You might also like