Patterns of parallel programming

Download Patterns of parallel programming

Post on 10-May-2015




6 download

Embed Size (px)


, by , Software Developer, CloudIt


<ul><li>1.Patterns of ParallelProgrammingPrepared by Yan Drugalya</li></ul> <p>2. Agenda Why parallel? Terms and measures Building Blocks Patterns overview Pipeline and data flow Producer-Consumer Map-Reduce Other 3. Why Moores law is not working anymore Power consumption Wire delays DRAM access latency Diminishing returns of more instruction-levelparallelism 4. Power consumptionSuns Surface10,000 1,000Rocket NozzlePower Density (W/cm2)100 Nuclear Reactor 10Pentium processors Hot Plate1 8080 70 80 90 0010 5. Wire delays 6. Diminishing returns 80s 10 CPI 1 CPI 90 1 CPI 0.5CPI 00s: multicore 7. No matter how fast processors get, softwareconsistently finds new ways to eat up the extraspeed. Herb Sutter 8. Survival To scale performance, put many processing cores on themicroprocessor chip New Moores law edition is about doubling of cores. 9. Terms &amp; Measures Work = T1 Span = T Work Law: Tp&gt;=T1/P Span Law: Tp&gt;=T Speedup: Tp/T1 Linear: (P) Perfect: P Parallelism: T1/T Tp Capitalize(ch)); 13. Task parallelismParallel.Invoke(() =&gt; Average(), () =&gt; Minimum() ); 14. Fork-Join Additional work may be started only when specific subsets of the original elements have completed processing All elements should be given the chance to run even if one invocation fails (Ping) Parallel.Invoke( () =&gt; ComputeMean(),Fork () =&gt; ComputeMedian(), () =&gt; ComputeMode());Compute Compute Computestatic void MyParallelInvoke(params Action[] actions) MedianMeanMode{var tasks = new Task[actions.Length];for (int i = 0; i &lt; actions.Length; i++)tasks[i] = Task.Factory.StartNew(actions[i]);JoinTask.WaitAll(tasks); } 15. Pipeline pattern Task T1 = Task.Factory.StartNew(() =&gt;Task 1 { return result1(); }); Task T2 = T1.ContinueWith((antecedent) =&gt;Task 2 { return result2(antecedent.Result); }); Task T3 = T2.ContinueWith((antecedent) =&gt;Task 3 { return result3(antecedent.Result); }); 16. Producer/ConsumerDisk/Net Read 1 Read 2Read 3BlockingCollection Process Process Process 17. Other patterns Speculative Execution APM (IAsyncResult, Begin/end pairs) EAP(Operation/Callback pairs) 18. References Patterns for Parallel Programming: Understanding and ApplyingParallel Patterns with the .NET Framework 4 Pluralsight: Introduction to Async and Parallel Programming in .NET 4 Async and Parallel Programming: Application Design The Free Lunch Is Over: A Fundamental Turn TowardConcurrency in Software Chapter 27 Multithreaded Algorithms from Introduction toalgorithms 3rd edition </p>


View more >