




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Topics in This Part Chapter 5 PRAM and Basic Algorithms Chapter 6A More Shared-Memory Algorithms Chapter 6B Implementation of Shared Memory Chapter 6C Shared-Memory Abstractions
Shared memory is the most intuitive parallel user interface:
Why Start with Shared Memory?
Study one extreme of parallel computation models:
In Part II″, we will study the other extreme case of models:
Everything else falls between these two extremes
5.1 PRAM Submodels and Assumptions
Fig. 4.6 Conceptual view of a parallel random-access machine (PRAM).
Processors
. . .
Shared Memory
0
1
p–
. . .
0 1 2 3
m–
Processor i can do the following in three phases of one cycle:
Types of CRCW PRAM
Undefined: The value written is undefined (CRCW-U)
Detecting: A special code for “detected collision” is written (CRCW-D)
Common: Allowed only if they all store the same value (CRCW-C) [ This is sometimes called the consistent-write submodel ]
Random: The value is randomly chosen from those offered (CRCW-R)
Priority: The processor with the lowest index succeeds (CRCW-P)
Max / Min: The largest / smallest of the values is written (CRCW-M)
Reduction: The arithmetic sum (CRCW-S), logical AND (CRCW-A), logical XOR (CRCW-X), or another combination of values is written
CRCW submodels are distinguished by the way they treat multiple writes:
Power of CRCW PRAM Submodels
Theorem 5.1: A p -processor CRCW-P (priority) PRAM can be simulated (emulated) by a p -processor EREW PRAM with slowdown factor Θ(log p ).
Intuitive justification for concurrent read emulation (write is similar): Write the p memory addresses in a list Sort the list of addresses in ascending order Remove all duplicate addresses Access data at desired addresses Replicate data via parallel prefix computation Each of these steps requires constant or O(log p ) time
Model U is more powerful than model V if T U( n ) = o( T V( n )) for some problem
EREW < CREW < CRCW-D < CRCW-C < CRCW-R < CRCW-P
1 6 5 2 3 6 1 1 2 1 1 1 2 2 3 5 6 6 1
2
3 5 6
Some Elementary PRAM Computations
Initializing an n -vector (base address = B ) to all 0s:
for j = 0 to n / p – 1 processor i do if jp + i < n then M [ B + jp + i ] := 0 endfor
Adding two n -vectors and storing the results in a third (base addresses B ′, B ″, B )
Convolution of two n -vectors: W (^) k = ∑ i + j = k Ui × Vj (base addresses BW , BU , BV )
n / p segments
p elements
5.2 Data Broadcasting
Fig. 5.2 Data broadcasting in EREW PRAM via recursive doubling.
Making p copies of B [0]
by recursive doubling
for k = 0 to log 2 p – 1
Proc j , 0 ≤ j < p , do Copy B [ j ] into B [ j + 2 k ]
endfor
0 1 2 3 4 5 6 7 8 9
10 11
B
Fig. 5.3 EREW PRAM data broadcasting without redundant copying.
0 1 2 3 4 5 6 7 8 9
10 11
B
Can modify the algorithm so that redundant copying does not occur and array bound is not exceeded
All-to-All Broadcasting on EREW PRAM
EREW PRAM algorithm for all-to-all broadcasting Processor j , 0 ≤ j < p , write own data value into B [ j ] for k = 1 to p – 1 Processor j , 0 ≤ j < p , do Read the data value in B [( j + k ) mod p ] endfor
This O( p )-step algorithm is time-optimal
Naive EREW PRAM sorting algorithm (using all-to-all broadcasting) Processor j , 0 ≤ j < p , write 0 into R [ j ] for k = 1 to p – 1 Processor j , 0 ≤ j < p , do l := ( j + k ) mod p if S [ l ] < S [ j ] or S [ l ] = S [ j ] and l < j then R [ j ] := R [ j ] + 1 endif endfor Processor j , 0 ≤ j < p , write S [ j ] into S [ R [ j ]]
j
This O( p )-step sorting algorithm is far from optimal; sorting is possible in O(log p ) time
p – 1
0
5.3 Semigroup or Fan-in Computation
EREW PRAM semigroup computation algorithm Proc j , 0 ≤ j < p , copy X [ j ] into S [ j ] s := 1 while s < p Proc j , 0 ≤ j < p – s , do S [ j + s ] := S [ j ] ⊗ S [ j + s ] s := 2 s endwhile Broadcast S [ p – 1] to all processors
If we use p processors on a list of size n = O( p log p ), then optimal speedup can be achieved
This algorithm is optimal for PRAM, but its speedup of O( p / log p ) is not
Fig. 5.4 Semigroup computation in EREW PRAM.
0 1 2 3 4 5 6 7 8 9
S 0: 1: 2: 3: 4: 5: 6: 7: 8: 9:
0: 0: 1: 2: 3: 4: 5: 6: 7: 8:
0: 0: 0: 0: 1: 2: 3: 4: 5: 6:
0: 0: 0: 0: 0: 0: 0: 0: 1: 2:
0: 0: 0: 0: 0: 0: 0: 0: 0: 0:
Fig. 5.5 Intuitive justification of why parallel slack helps improve the efficiency.
Higher degree of parallelism near the leaves
Lower degree of parallelism near the root
A Divide-and-Conquer Parallel-Prefix Algorithm
Fig. 5.7 Parallel prefix computation using a divide-and-conquer scheme.
⊗ ⊗ ⊗ ⊗ ⊗
⊗ ⊗ ⊗ ⊗
x 0 x 1 x 2 x 3 x (^) n -2 x (^) n -
0: 0:
0: 0:
0: n - 0: n -
In hardware, this is the basis for Brent-Kung carry-lookahead adder
T ( p ) = T ( p /2) + 2
T ( p ) ≅ 2 log 2 p
Each vertical line represents a location in shared memory
Another Divide-and-Conquer Algorithm
Fig. 5.8 Another divide-and-conquer scheme for parallel prefix computation.
Strictly optimal algorithm, but requires commutativity
x 0 x 1 x 2 x 3 x (^) n -2 x (^) n -
0: n - 0: n -
Parallel prefix comput ation on n / odd-indexed inputs
Parallel prefix comput ation on n / even-index ed inputs
⊗ ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ ⊗ ⊗
T ( p ) = T ( p /2) + 1
T ( p ) = log 2 p
Each vertical line represents a location in shared memory
List Ranking via Recursive Doubling
Fig. 5.11 Element ranks initially and after each of the three iterations.
Many problems that appear to be unparallelizable to the uninitiated are parallelizable; Intuition can be quite misleading!
1 1 1 1 1 0
2 2 2 2 1 0
4 4 3 2 1 0
5 4 3 2 1 0
A B C D E F 4 3 5 3 1 0
info next 0 1 2 3 4 5
head
PRAM List Ranking Algorithm
Question: Which PRAM submodel is implicit in this algorithm?
If we do not want to modify the original list, we simply make a copy of it first, in constant time
A B C D E F 4 3 5 3 1 0
info next^ rank 0 1 2 3 4 5
head
PRAM list ranking algorithm (via pointer jumping) Processor j , 0 ≤ j < p , do {initialize the partial ranks} if next [ j ] = j then rank [ j ] := 0 else rank [ j ] := 1 endif while rank [ next [ head ]] ≠ 0 Processor j , 0 ≤ j < p , do rank [ j ] := rank [ j ] + rank [ next [ j ]] next [ j ] := next [ next [ j ]] endwhile
Answer: CREW