1 sorting networks. 2 10 9 4 3 2 1 8 7 9 4 3 2 1 8 7 sorting
DESCRIPTION
3 Sorting Network (Bitonic Sorting Network)TRANSCRIPT
1
Sorting Networks
2
10
94
3
21
87
109
4321
87
Sorting
3
Sorting Network
(Bitonic Sorting Network)
4
Sorting Network
(Bitonic Sorting Network)
5
Comparator
x
y
max(x,y)
min(x,y)
6
Comparatormax
min
1
9
9
1
7
Comparatormax
min
100
4
100
4
8
9
Levels1 2 3
Depth = 3
Width = 4
10
1825
11
18
25
Level 1
12
1
8
2
5
Level 2
13
1
8
25
Level 3
14
1
8
25
1825
Input Output
15
10
94
3
21
87
109
4321
87
Input Output
16
10
94
3
21
87
109
4321
87
1 2 3 4 5 6levels
17
Sort(n)
Sort(n/2)
Sort(n/2)
Merge(n)In Out
)(log2 nOdepth
Recursive construction of Bitonic Sorting Network
18
Merge(n)
Merge(n/2)
Merge(n/2)
)(lognOdepth
Recursive construction of merging network
19
Induction BasisSort(2)
Merge(2)
20
Width
Sorting network depth:
)(log2log...4log2loglog 2nOnnn
n
)(log2 nO
Mergerwidth n
Totaldepth
2n
4n 2
21
Counting Networks
22
The Counting Problem
0
Shared variable
23
0
Token = Increment request
Shared variable
24
1
Increment request
Shared variable
0
25
1
Shared variable
26
1
Increment request
Shared variable
27
2
Shared variable
1Increment request
28
2
Shared variable
29
2
Increment request
Shared variable
30
3
Increment request
Shared variable
2
31
6
Sequential Bottleneck
Shared variable
The requests have to be serialized
01 2 3
45
32
Counting Network
Inputs Outputs
33
Counting Network
34
Balancer
Inputs Outputs
Token
35
Balancer
Inputs Outputs
36
Balancer
37
Balancer
38
Balancer
39
Balancer
40
Balancer
41
Balancer
42
Balancer
All tokens together
43
Balancer
Step property
44
Balancer
Step property
Another example
45
Balancer
Step property
Another example
46
Balancer
Step property
Another example
47
Counting Network
(Bitonic Counting Network)
48
Counting Network
49
Counting Network
50
Counting Network
51
Counting Network
52
Counting Network
53
Counting Network
54
Counting Network
55
Counting Network
56
Counting Network
57
Counting Network
58
Counting Network
59
Counting Network
60
Counting Network
61
Counting Network
62
Counting Network
63
Counting Network
64
Counting Network
65
Counting Network
All tokens
66
Counting Network
All tokens Step property
67
Counting Network
Another example Step property
68
Counting Network
Another example Step property
69
Counting Network
Another example Step property
70
Counting Network
Another example Step property
71
Counting Network
ParallelismMany increment requests are processed simultaneously
72
Counting
0123
Token = Increment request
Output Shared variables
73
Counting
0123
Output Shared variables
74
Counting
4123
0Returned value
Shared variable value is increased by 4 (output width)
75
Counting
4123
0
Increment request
76
Counting
4123
0
77
Counting
4523
0
1
Returned value
78
Counting
4523
0
1
Increment request
79
Counting
4563
0
1
2
Returned value
80
Counting
4563
0
1
2
81
Counting
4567
0
1
2
3
Returned value
82
Counting
4567
0
1
2
3
83
Counting
8567
0
1
2
3
4Returned value
84
Counting
8567
0
1
2
3
4
85
Counting
8967
0
1
2
3
4
5
Returned value
86
Counting
8967
0
1
2
3
4
5
All tokens
87
Bitonic Counting Network
Isomorphic to Bitonic Sorting Network
88
Count(n)
Count(n/2)
Count(n/2)
Merge(n)In Out
)(log2 nOdepth
X
Y
Z
89
Merge(n)
Merge1(n/2)
Merge2(n/2)
)(lognOdepth
X
Y
Z
StepProp.
StepProp.
StepProp.
90
X
0x1x2x3x4x5x6x7x
oddX
0x1x2x3x4x5x6x7x
evenX
0x1x2x3x4x5x6x7x
Even subsequence
Odd subsequence
91
Merge(n)
Merge1(n/2)
Merge2(n/2)
X
Y
Z
evenX
oddY
evenY
oddX
A
B
92
Theorem:
Proof:The proof is by induction on n
For the merger is a balancer andthe claim holds trivially.
2nInduction Basis:
The merger(n) produces output Z with step property if both inputs X and Y have step property
93
Induction Hypothesis:
Merge(n/2)
If step sequence
If step sequence
Then stepsequence
Assume that every merger of size n/2 and smallerperforms merging properly
94
Merge(n)
Induction step:
If step
If stepThen step
We want to show that:
X
YZ
Suppose and have the step property.Then we show that has the step property
X YZ
95
0x
2x
4x
6x
1x
3x
5x
7x
evenX
oddX
0x1x2x3x4x5x6x7x
X
If has the step propertythen and have the step property
XevenX oddX
Tokens
96
Merge1(n/2)evenX
oddYA
Merge2(n/2)evenY
oddX
B
step
step
step
step
step
step
Therefore, from induction hypothesis:
Output sequence
Output sequence
97
First, we show: 1||||1 BA
Where denotes the total number oftokens in sequence
||AA
98
We have: |||||| oddeven YXA
|||||| oddeven XYB
Merger 1
Merger 2
99
|||| oddeven XX 1|||| oddeven XXor0x1x2x3x4x5x6x7x
0x1x2x3x4x5x6x7x
Since has the step property:X
Therefore: 1||||0 oddeven XX
Similarly: 1||||0 oddeven YY
100
|)||(||)||(||||| evenoddoddeven YYXXBA
1||||0 oddeven XX
1||||0 oddeven YY
1||||1 BA
101
Now, we show that has the step propertyZ
1||||1 BA
A Bc
i i
ccc
1c 1c1c1c
ccccc
1c1c1c
There is at most one wire where the two sequences differ
#tokens
i
#tokensstep step
102
A
B
c
i
i
ccc1c1c1c1c
ccccc
1c1c1c
cccc
c1c
1c1c
1c1c
cccc
c1c
1c1c
1c1c
Z
Stepproperty
Mer
ge1(
n/2)
Mer
ge(n
/2)
Merge(n)