Wave Algorithm
Why waves ?
■ Basic Bloc : Generic subroutine in the design of distributed algorithms
■ Examples of use :
- Broadcast, Routing, Communication Protocols
- Leader Election
- Resource Sharing, Mutual Exclusion
- Graph Algorithms for Search, Spanning Trees, etc
- Synchronization
- Wake-up
- Deadlock, Termination Detection
- Reset Protocols
- Resource Allocation
- Distributed Sorting, Ranking, etc.
Specification
A wave algorithm is a distributed algorithm that satisfies the following requirements:
■Termination : Each computation is finite
■Decision : Each computation contains at least one decide event
■Dependence : In each computation every decide event is causally preceded by an event in each process
Algorithms
■ Sequential Design
■ Token Ring
■ Depth-First Token Circulation
■ DFTC over Tree Networks
■ Parallel Design
■ Propagation of Information with Feedback
■ Wave Algorithm for Tree Networks
■ Another BFS Algorithm
Token Ring
Token Ring
Base of Protocol IEEE 802.5
Token Ring
var !"#$% : port label //Process % is an initiator
upon external initialization do send <&'(> to !"#$%;
done
upon receipt of <tok> from q do decide
done
//Process % is not an initiator
upon receipt of <tok> from q do send <&'(> to !"#$%;
done
Decide
Token Ring
•
Sequential•
Ring•
Central•
Number of messages : N•
Time : N•
Size of messages (overhead) : 0Depth-First Token
Circulation
//Process % is an initiator
upon external initialization do Parent% = ⊤;
Next();
//For any Process %
upon receipt of <tok> from q If Parent% = ⊥
then Parent% = q;
fi
If L% = used% then Decide
else if q ≠ Current% ⋀ q ≠ Parent% then used% = used% ∪ {Parent%}
send <&'(> to q;
else Next();
fi fi
var Parent%, Current% : port label ∈ L% ∪ {⊥,⊤}, init ⊥;
used% : set of port labels, init ∅;
DFTC
Procedure Next()
If ∃ q’ ∈ L% \ (used% ∪ {Parent%})
then Current% = q’ ∈ L% \ (used% ∪ {Parent%})
used% = used% ∪ {Current%}
send <&'(> to Current%; else used% = used% ∪ {Parent%}
send <&'(> to Parent%;
•
Sequential•
Arbitrary topology•
Central•
Number of messages : 2M•
Time : 2M•
Size of messages (overhead) : 0 (poss. root’s Id)DFTC
DFTC over trees
■
We are given two distributed algorithms:
■
One for constructing a tree in a general network
■
DFTC
3 3
2 1 2
1
r
1
2
2
1
3
3 3
2 1 2
1
r
1
2
2
1
3
a b
c d
l
i
r
j
e
f
g
k
DFTC over trees
d
c a c b c d e
d r g
f k f
g r
j r
i
l
i
r
a b
c d
l
i
r
j
e
f
g
k
•
Sequential•
(Spanning) Tree topology•
Number of messages : 2N-2•
Time : 2N-2•
Size of messages (overhead) : 0 (poss. root’s Id)•
Direct application : Mutual ExclusionDFTC over trees
Propagation of Information with
Feedback
Synchronous r
//Process % is an initiator
upon external initialization do Parent% = ⊤;
∀ q ∈ L% : send <&'(> to q;
var Parent% : port label ∈ L% ∪ {⊥,⊤}, init ⊥;
used% : set of port labels, init ∅;
PIF
//For any Process %
upon receipt of <tok> from q used% = used% ∪ {q};
If Parent% = ⊥ then Parent% = q;
∀ q’ ∈ L% \ {q}: send <&'(> to q’;
fi
If used% = L%
then If Parent% = ⊤ then decide;
else send <&'(> to Parent%; fi
fi
•
Parallel•
Arbitrary Topology•
Central•
Number of messages : 2M•
Time : O(N)•
Size of messages (overhead) : 0 (poss. root’s Id)PIF
Waves over Trees
WA over Tree Networks
F G I
K
H A
C
N D
L
J E
B
M
Décide Décide
//Process % is a leaf/Initiator upon external initialization do
Let q ∈ L%;
send <&'(> to q;
//For any Process %
upon receipt of <tok> from q used% = used% ∪ {q};
If ∃ q ∈ Lp : q ∉ used% ⋀ used% ∪ {q} = Lp ⋀ ¬ Sentp then send <&'(> to q;
Sent% = true;
fi
If used% = Lp then Decide;
fi var Sent% : boolean, init false;
used% : set of port labels, init ∅;
•
Parallel•
Tree Topology•
(Semi-)distributed•
Number of messages : N•
Time : O(D)•
Size of messages (overhead) : 0WA over Tree Networks
Another BFS Algorithm
var Parent% : port label ∈ L% ∪ {⊥}, init ⊥;
Diff% : array[q ∈ L% ] of {-1,0,1}, init 0;
BFS
//For any Process % ≠ rootloop
If ∀ q ∈ L% : Diff% [q] ≥ 0 then for all q ∈ L% do
Diff% [q] = Diff% [q] - 1;
done
Parent% = q| Diff% [q] = -1;
∀ q ∈ L% : send <INCR> to q;
fi end loop
upon receipt of <INCR> from q Diff% [q] = Diff% [q] + 1;
Parent% = q| Diff% [q] = -1;
r
00 0 0
0 0 0
0 0
0 0
00 0
00 0 0 0
0 0 000 0 00 0 00 0
0 00 0
0 00 0
0 0
0 0
0