Analysis of Algorithms : An Active Learning Approach

(Ron) #1
7.5 PARALLEL SORTING 195

■ 7.5.2 Odd-Even Swap Sort
In previous sections, we were able to reduce costs by reducing the number of
processors. We can cut the number of processors needed in half with the fol-
lowing sorting method, which compares adjacent values and swaps them if
they are out of order.
for j = 1 to N/2 do
Parallel Start
for k = 1 to N/2 do
Pk compares M2k-1 and M2k

L

14 16

11 12 13 15 17 18

19

P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9

M

15 17 19

P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9

N

16 18

P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9

O 11

11 12 13 14 15 17 19

11 12 13 14 16 18

12 13 14 15 16 18

17 19

P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9

P 11 12 13 14 15 16 17 19

18

P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9

Q

11 12 13 14 15 16 17 18 19

P 1 P 2 P 3 P 4 P 5 P 6 P 7 P 8 P 9
■FIGURE 7.4C
A linear parallel
network sort

Free download pdf