
































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
the complete guide to parallel algorithms
Typology: Thesis
1 / 40
This page cannot be seen from the preview
Don't miss anything!

































Parallel Sorting:-
i
j
Sorting: Parallel Compare Exchange Operation
A parallel compare-exchange operation. Processes P
i
and P
j
send their elements to each other. Process P
i
keeps min{a
i
,a
j
}, and P
j
keeps max{a
i
, a
j
Cont…
Average optimal sequential complexity: O(n log n)
Parallel efficiency limitations
Partitions are unbalanced
A single processor performs the initial
partitioning
Example of quicksort
Let S = (6,5 ,9,2,4,3,5 , 1, 7,5,8 ).
T he first call to procedure Q U I C K S O R T
produces 5 as the median element of S, and hence
S1 = {2,4,3,1,5,5} and
Note that S1 = 6 and S2= 5. A recursive call to Q U I
C K S O R T with S, as input produces the two
subsequences {2,1,3} and {4,5,5}. The second call
with S, as input produces {6,5,7}an d {9,8}. Further
recursive calls complete the sorting of these
sequences.
For some constant c, we can express the running
time of procedure
QUICKSORT as
= O(n log n),
1.2 A NETWORK FOR SORTING
It is rather straightforward to use a collection of
merging networks
to build a sorting network for the sequence S = {s1,
s2,... , sn), where n is a power of 2. The idea is the
following.
In a first stage, a rank of n/2 comparators is used to
create n/2 sorted sequences each of length 2.
In a second stage, pairs of these are now merged into
sorted sequences of length 4 using a rank of (2,2)-
merging networks. Again, in a
FI G : ODD EVEN SORTI NG NE TWO RK FO R SEQ UENCE OF EI GHT E LEM ENTS
The odd-even sorting network is impractical for large input
sequences :
(i) The network is extremely fast. It can sort a sequence of
length 2^20 within, on the order of, (20)2 time units.
This is to be contrasted with the time required by
procedure QUICKSORT, which would be in excess of
20 million time units.[(log n)^2]
(ii) The number of comparators is too high. Again for n =
2^20, the network would need on the order of 400 million
comparators.[n (log n)^2]
(iii) The architecture is highly irregular and the wires linking
the comparators have lengths that vary with n.
Odd-Even Transposition Sort
Variation of bubble sort.
Operates in two alternating phases, even phase
and odd phase.
Even phase
Even-numbered processes exchange numbers
with their right neighbour.
Odd phase
Odd-numbered processes exchange numbers with
their right neighbour.
Parallel time complexity: T
par
= O( n ) (for P=n)
MERGE SPLIT:-
Now consider the second approach. If N processors,
where N < n,
Assume that each of the N processors in the linear array
holds a subsequence of S of length n/N.
The comparison-exchange operations of procedure
ODD-EVEN TRANSPOSITION are now replaced with
merge-split operations on subsequences.
Let Si denote the subsequence held by processor Pi.
Initially, the Si are random subsequences of S.
Sorting sequence of twelve elements using procedure