PCP 2022 6 ParallelAlgorithms PartI
PCP 2022 6 ParallelAlgorithms PartI
producer-consumer problem
executors thread pools timing
Dining philosphoers problem
The DAG, or “cost graph”
Checkpoint:
What is the span of this DAG?
What is the work?
y i = f i (x i )
DAG for an embarrassingly parallel algorithm
or, indeed:
y i = f i (x i )
Image Processing
19
Examples of divide and conquer algorithms
• Finding maximum or minimum element
• Is there an element satisfying some property (e.g., is there a 17)?
• Left-most element satisfying some property (e.g., first 17)
• What should the recursive tasks return?
• How should we merge the results?
• Corners of a rectangle containing all points (a “bounding box”)
• Counts, e.g. number of strings that start with a vowel
• This is just summing with a different base case
• Many problems are!
divide
base cases
combine
results
divide
base cases
combine
results
+ + + + + + + +
+ + + +
+ +
+
• Anything that can use results from two halves and merge them in
O(1) time has the same property…
23
Basic Divide-and-Conquer algorithms: Reductions
}
Maps in ForkJoin Framework
Even though there is no result-combining, it still helps
with load balancing to create many small tasks
• Maybe not for vector-add but for more compute-
intensive maps
• The forking is O(log n) whereas theoretically other
approaches to vector-add is O(1)
Historical note:
• Original algorithm due to R. Ladner and M. Fischer at the
University of Washington in 1977
input 6 4 16 10 16 14 2 8
output
slide from: Sophomoric Parallelism and Concurrency, Lecture 3 32
range 0,8
Example sum 76
fromleft 0
input 6 4 16 10 16 14 2 8
output 6 10 26 36 52 66 68 76
slide from: Sophomoric Parallelism and Concurrency, Lecture 3 33
range 0,8
sum 76
fromleft 0
input 6 4 16 10 16 14 2 8
output 6 10 26 36 52 66 68 76
slide from: Sophomoric Parallelism and Concurrency, Lecture 3 34
The algorithm, part 1
• Up:
just a sum, have leaf node hold the sum of a range
• Down:
output[lo] = fromLeft + input[lo];
for(i=lo+1; i < hi; i++)
output[i] = output[i-1] + input[i]