Lecture 9: Oblivious and Non-Oblivious Algorithms
Total Page:16
File Type:pdf, Size:1020Kb
spcl.inf.ethz.ch @spcl_eth T. HOEFLER, M. PUESCHEL Lecture 9: Oblivious and non-oblivious algorithms Teaching assistant: Salvatore Di Girolamo Motivational video: https://www.youtube.com/watch?v=qx2dRIQXnbs spcl.inf.ethz.ch @spcl_eth How many measurements are needed? . Measurements can be expensive! . Yet necessary to reach certain confidence . How to determine the minimal number of measurements? . Measure until the confidence interval has a certain acceptable width . For example, measure until the 95% CI is within 5% of the mean/median . Can be computed analytically assuming normal data . Compute iteratively for nonparametric statistics . Often heard: “we cannot afford more than a single measurement” . E.g., Gordon Bell runs . Well, then one cannot say anything about the variance Even 3-4 measurement can provide very tight CI (assuming normality) Can also exploit repetitive nature of many applications TH, Belli: Scientific Benchmarking of Parallel Computing Systems, IEEE/ACM SC15 2 spcl.inf.ethz.ch @spcl_eth Experimental design I don’t believe you, try other numbers of processes! MPI_Reduce behaves much simpler! Rule 9: Document all varying factors and their levels as well as the complete experimental setup (e.g., software, hardware, techniques) to facilitate reproducibility and provide interpretability. We recommend factorial design . Consider parameters such as node allocation, process-to-node mapping, network or node contention . If they cannot be controlled easily, use randomization and model them as random variable . This is hard in practice and not easy to capture in rules TH, Belli: Scientific Benchmarking of Parallel Computing Systems, IEEE/ACM SC15 3 spcl.inf.ethz.ch @spcl_eth Time in parallel systems That’s nonsense! My simple broadcast takes only one latency! But I measured it so it must be true! … Measure each t = -MPI_Wtime(); operation for(i=0; i<1000; i++) { separately! MPI_Bcast(…); } t += MPI_Wtime(); t /= 1000; 4 spcl.inf.ethz.ch @spcl_eth Summarizing times in parallel systems! Come on, show me the data! My new reduce takes only 30us on 64 ranks. Rule 10: For parallel time measurements, report all measurement, (optional) synchronization, and summarization techniques. Measure events separately . Use high-precision timers . Synchronize processes . Summarize across processes: . Min/max (unstable), average, median – depends on use-case TH, Belli: Scientific Benchmarking of Parallel Computing Systems, IEEE/ACM SC15 5 spcl.inf.ethz.ch @spcl_eth Give times a meaning! I have no clue. I compute 1010 digits of Pi in 2ms on Dora! Rule 11: If possible, show upper performance bounds to facilitate interpretability of the measured results. Model computer system as k-dimensional space . Each dimension represents a capability Can you provide? Floating point, Integer, memory bandwidth, cache bandwidth, etc. - Ideal speedup Ok: The. Featurescode runs are typical rates - Amdahl’s speedup 17ms. onDetermine a single maximum rate for each dimension - Parallel overheads core, 0.2ms are E.g., from documentation or benchmarks initialization and it has. oneCan reduction! be used to proof optimality of implementation . If the requirements of the bottleneck dimension are minimal TH, Belli: Scientific Benchmarking of Parallel Computing Systems, IEEE/ACM SC15 6 spcl.inf.ethz.ch @spcl_eth Plot as much information as possible! My most common request was “show me the data” Rule 12: Plot as much information as needed to interpret the experimental results. Only connect measurements by lines if they indicate trends and the interpolation is valid. This is how I should have presented the Dora results. TH, Belli: Scientific Benchmarking of Parallel Computing Systems, IEEE/ACM SC15 7 spcl.inf.ethz.ch @spcl_eth Administrivia . Final project presentation: next Monday 12/17 during lecture . Report will be due in January! Starting to write early is very helpful --- write – rewrite – rewrite (no joke!) . Coordinate your talk! You have 10 minutes (8 talk + 2 Q&A) What happened since the intermediate report? Focus on the key aspects (time is tight)! Try to wrap up – only minor things left for final report. Engage the audience . Send slides by Sunday night (11:59pm Zurich time) to Salvatore! We will use a single (windows) laptop to avoid delays when switching Expect only Windows (powerpoint) or a PDF viewer The order of talks will again be randomized for fairness 8 spcl.inf.ethz.ch @spcl_eth Review of last lecture(s) . Impossibility of wait-free consensus with atomic registers . “perhaps one of the most striking impossibility results in Computer Science” (Herlihy, Shavit) . Large-scale locks . Scaling MCS to thousands of nodes with (MPI) RMA . Oblivious algorithms . Execution oblivious vs. structural oblivious . Why do we care about obliviousness? . Strict optimality of work and depth – reduction – scan Linear scan, tree scan, dissemination scan, surprising work-depth tradeoff W+D ≥ 2n-2 . I/O complexity . The red-blue pebble game (four rules: input, output, compute, delete) . S partitioning proof . Geometric arguments for dense linear algebra – example matrix multiplication Loomis Whitney inequality: 푉 ≤ 푉푥 + 푉푦 + |푉푧| (a set is smaller than sqrt of the sum of orthogonal projections) . Simple recomputation – trade off I/O for compute 9 spcl.inf.ethz.ch @spcl_eth Learning goals for today . Strict optimality . Work/depth tradeoffs and bounds . Applications of prefix sums Parallelize seemingly sequential algorithms . Oblivious graph algorithms . Shortest paths . Connected components . Nonoblivious algorithms . Sums and prefix sums on linked lists . Connected components . Distributed algorithms . Broadcast in alpha-beta and LogP 10 spcl.inf.ethz.ch @spcl_eth DPHPC Overview 11 spcl.inf.ethz.ch @spcl_eth Recap: Work-depth tradeoff in parallel prefix sums . Obvious question: is there a depth- and work-optimal algorithm? . This took years to settle! The answer is surprisingly: no . We know, for parallel prefix: 푊 + 퐷 ≥ 2푛 − 2 Output tree: • leaves are all inputs, rooted at 푥푛 푥1 푥2 푥3 푥4 푥5 푥6 푥7 푥8 • binary due to binary operation • 푊 = 푛 − 1, 퐷 = 퐷표 Input tree: trees may only overlap at the “ridge” • rooted at 푥1, leaves are all outputs • not binary (simultaneous read) • 푊 = 푛 − 1 Ridge can be at most 퐷표long! Now add trees and subtract shared vertices: 푛 − 1 + 푛 − 1 − 퐷표 = 2푛 − 2 − 퐷표 ≤ 푊 q.e.d. 푥 + ⋯ + 푥 1 8 12 spcl.inf.ethz.ch @spcl_eth Work-Depth Tradeoffs and deficiency “The deficiency of a prefix circuit 푐 is defined as def 푐 = 푊푐 + 퐷푐 − (2푛 − 2)” 1960 Latest 2006 result for zero-deficiency 푛 > 퐹 퐷 + 3 − 1 W-D tradeoff: 1986 construction for (푓 푛 is inverse) From Zhu et al.: “Construction of Zero-Deficiency Parallel Prefix Circuits”, 2006 13 spcl.inf.ethz.ch @spcl_eth Work- and depth-optimal constructions . Work-optimal? . Only sequential! Why? . 푊 = 푛 − 1, thus 퐷 = 2푛 − 2 − 푊 = 푛 − 1 q.e.d. . Depth-optimal? . Ladner and Fischer propose a construction for work-efficient circuits with minimal depth 퐷 = ⌈log2 푛⌉, 푊 ≤ 4푛 Simple set of recursive construction rules (too boring for class, check 1980’s paper if needed) Has an unbounded fan-out! May thus not be practical . Depth-optimal with bounded fan-out? . Some constructions exist, interesting open problem . Nice research topic to define optimal circuits 14 spcl.inf.ethz.ch @spcl_eth But why do we care about this prefix sum so much? . It’s the simplest problem to demonstrate and prove W-D tradeoffs . And it’s one of the most important parallel primitives . Prefix summation as function composition is extremely powerful! . Many seemingly sequential problems can be parallelized! . Simple first example: binary adder – 푠 = 푎 + 푏 (n-bit numbers) . Starting with single-bit (full) adder for bit i Example 4-bit ripple carry adder 푎푖 푏푖 Question: what are the functions for 푠푖and 푐표푢푡,푖? 푠푖 = 푎푖 xor 푏푖 xor 푐푖푛,푖 푐 푐 푖푛, 푖 표푢푡, 푖 + 푐표푢푡,푖 = 푎푖 and 푏푖 or 푐푖푛,푖 and (푎푖 xor 푏푖) 푠푖 Show example 4-bit addition! Question: what is work and depth? source: electronics-tutorials.ws 15 spcl.inf.ethz.ch @spcl_eth Seems very sequential, can this be parallelized? . We only want 풔! 푐표푢푡,푖 = 푎푖 and 푏푖 or 푐푖푛,푖 and (푎푖 xor 푏푖) 푠 = 푎 xor 푏 xor 푐 . Requires 푐푖푛,1, 푐푖푛,2, … , 푐푖푛,푛 though 푖 푖 푖 푖푛,푖 . Carry bits can be computed with a scan! source: electronics-tutorials.ws . Model carry bit as state starting with 0 1 0 Encode state as 1-hot vector: 푞0 = 0 , 푞1 = 1 . Each full adder updates the carry bit state according to 푎푖 and 푏푖 State update is now represented by matrix operator, depending on 푎푖 and 푏푖 (푀푎푖푏푖): 1 1 1 0 0 0 푀 = , 푀 = 푀 = , 푀 = 00 0 0 10 01 0 1 11 1 1 . Operator composition is defined on algebraic ring ({0, 1, or, and}) – i.e., replace “+” with “and” and “*” with “or” Prefix sum on the states computes now all carry bits in parallel! . Example: a=011, b=101 푴ퟏퟏ, 푴ퟏퟎ, 푴ퟎퟏ 0 0 0 0 0 0 . Scan computes: 푀 = ; 푀 푀 = ; 푀 푀 푀 = in parallel 11 1 1 11 10 1 1 11 10 01 1 1 . All carry states and 푠푖 can now be computed in parallel by multiplying scan result with 푞0 16 spcl.inf.ethz.ch @spcl_eth Prefix sums as magic bullet for other seemingly sequential algorithms . Any time a sequential chain can be modeled as function composition! . Let 푓1, … , 푓푛 be an ordered set of functions and 푓0 푥 = 푥 . Define ordered function compositions: 푓1(푥); 푓2(푓1 푥 ); … ; 푓푛(… 푓1 푥 ) . If we can write function composition 푔 푥 = 푓푖(푓푖−1 푥 ) as 푔 = 푓푖 ∘ 푓푖−1 then we can compute ∘ with a prefix sum! We saw an example with the adder (푀푎푏 were our functions) . Example: linear recurrence 풇풊 풙 = 풂풊풇풊−ퟏ 풙 + 풃풊 with 풇ퟎ 풙 =x 푎 푏 . Write as matrix form 푓 푥 = 푖 푖 푓 푥 푖 1 0 1 푖−1 1 .