Parallel Algorithm & Sorting in Parallel Programming: Submitted By:-Submitted To: - Dalpat Songra
Parallel Algorithm & Sorting in Parallel Programming: Submitted By:-Submitted To: - Dalpat Songra
Programming
0 0 0 0
0 1 0 0
1 1 0
1
Cont...
Update si array
i: 1+ci position
5: 1+2=3
2: 1+0=1
3:1+1=2
4:1+3=4
Cont......
Analysis:- Each of steps 1 and 2 consists of an
operation requiring constant time. Therefore
Running Time t(n) = O(1).
Since p(n) = n2
The cost of procedure CRCW SORT is:-
C(n)= O(n2) (which is not optimal)
1.5 SORTING ON THE CREW MODEL
Our purpose is to design an algorithm that is:
1. free of write conflicts.
2. uses a reasonable number of processors.
3. a running time that is small and adaptive.
4. a cost that is optimal.
Assume that a CREW SM SIMD computer with N
processors PI, P2. . . , PN is to be used to sort the
sequence S = {s1 s2 . . . , sn), where N < n.
Algorithm:-
procedure CREW SORT (S)
Step 1: for i = 1 to N do in parallel
Processor Pi
(1.1) reads a distinct subsequence Si of S of size n/N
(1.2) QUICKSORT (Si)
(1.3) Si1 <- Si
(1.4) Pi1 <- Pi O((n/N)log(n/N))
end for.
Cont…
Step 2 (2.1) u =1
(2.2) v = N
(2.3) while v > 1 do
(2.3.1) for m = 1 to |_v/2_| do in parallel
(i) Pu+1m <- Pu 2m-1 U pu 2m
(ii) The processors in the set Pu+1mperform
CREW MERGE (su 2m-1, su 2m, su+1 m)
end for
(2.3.2) if v is odd then
(1) pU+1 v/2 = pu v O((n/N) + log n)
time
(ii) sU+1 v/2 = sU V
end if
(2.3.3) u = u + 1
(2.3.4) V = v/2
end while.
Example
Let S = (2, 8, 5, 10, 15, 1, 12, 6, 14, 3, 11, 7, 9, 4, 13, 16) and N
= 4. Here N<n