1 / 61
Recap: Brent‘s principle
- Sequential algorithms: time = work
- Parallel algorithms (PRAM):
– time T(n) – work W(n)
- Brent‘s princliple:
- Work matters!
Recap: Brents principle Sequential algorithms: time = work Parallel - - PowerPoint PPT Presentation
Recap: Brents principle Sequential algorithms: time = work Parallel algorithms (PRAM): time T(n) work W(n) Brents princliple: Work matters! 1 / 61 Work efficiency Parallel alg is work-efficient if: Work is the
1 / 61
– time T(n) – work W(n)
2 / 61
– Work is the same as sequential algorithm:
3 / 61
– Work is the same as sequential algorithm:
4 / 61
3 1 1 7 2 5 9 2 4 3 3 3 4 5 12 14 19 28 30 34 37 40
5 / 61
3 1 1 7 2 5 9 2 4 3 3
6 / 61
3 1 1 7 2 5 9 2 4 3 3 3
7 / 61
3 1 1 7 2 5 9 2 4 3 3 3 4
8 / 61
3 1 1 7 2 5 9 2 4 3 3 3 4 5
9 / 61
3 1 1 7 2 5 9 2 4 3 3
3 4 5 12 14 19 28 30 34 37 40
10 / 61
11 / 61
12 / 61
13 / 61
15 / 61
– Except all cells need correct values
– Add values of increasing distance
16 / 61
3 1 1 7 2 5 9 2 3 4 2 8 9 7 14 11
17 / 61
3 1 1 7 2 5 9 2 3 4 2 8 9 7 14 11 3 4 5 12 11 23 18 15
18 / 61
3 1 1 7 2 5 9 2 3 4 2 8 9 7 14 11 3 4 5 12 11 23 18 15 3 4 5 12 14 28 30 19
19 / 61
– Let‘s prove it:
– the first 2j elements are prefix sums, – each A[i] = sum of previous 2j elements
3 1 1 7 2 5 9 2 3 4 2 8 9 7 14 11 3 4 5 12 11 23 18 15
20 / 61
21 / 61
22 / 61
23 / 61
24 / 61
– Remember: we have unlimited processors!
25 / 61
– Inner loop is done in parallel: O(1) – Outer loop is sequential: O(log n)
26 / 61
27 / 61
28 / 61
29 / 61
30 / 61
31 / 61
32 / 61
3 4 5 12 3 1 1 7 2 5 9 2
33 / 61
4 12 19 30 3 1 1 7 2 5 9 2
34 / 61
4 12 19 30 3 1 1 7 2 5 9 2
3 5 14 28
35 / 61
– Depth of a tree is O(log n) – Number of nodes is O(n)
36 / 61
3 1 1 7 2 5 9 2 4 8 7 11
37 / 61
3 1 1 7 2 5 9 2 4 8 7 11
4 12 7 18
38 / 61
3 1 1 7 2 5 9 2 4 8 7 11
4 12 7 18 4 12 7 30
39 / 61
3 1 1 7 2 5 9 2
4 12 7 30
40 / 61
3 1 1 7 2 5 9 2
4 12 19 30
4 12 7 30
41 / 61
– Easier to use consecutive spaces – Compress to the first n/2 positons
3 1 1 7 2 5 9 2
4 12 19 30
42 / 61
3 1 1 7 2 5 9 2
4 12 19 30
43 / 61
44 / 61
45 / 61
46 / 61
47 / 61
– Can be done in parallel: – Solution?
48 / 61
– Can be done in parallel: – Solution?
49 / 61
– Solution?
50 / 61
– Solution? – (or using the Master Theorem)
51 / 61
52 / 61
53 / 61
1
1 3 2 4 1 1 3 2 6 1 8 4 2 1 2
54 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 4 6 2 5 7 12 3 3
55 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 4 6 2 5 7 12 3 3 8 12 15 7
56 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 4 6 2 5 7 12 3 3 8 12 15 7 27 15
57 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 4 6 2 5 7 12 3 3 8 12 15 7 27 15 42
58 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 4 6 2 5 7 12 3 3 8 12 15 7 42 15 42
59 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 4 6 2 5 7 12 3 3 15 27 42 7 42 15 42
60 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 7 13 15 20 27 39 42 3 15 27 42 7 42 15 42
61 / 61
1 1 3 2 4 1 1 3 2 6 1 8 4 2 1 2 7 13 15 20 27 39 42 3 15 27 42 7 42 15 42
62 / 61
3 4 7 9 13 14 15 18 20 26 27 35 39 41 42 2 7 13 15 20 27 39 42 3 15 27 42 7 42 15 42