parallel programming in modern world .net technics shared
TRANSCRIPT
![Page 1: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/1.jpg)
Parallel programming in modern world.NET TECHNICS
![Page 2: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/2.jpg)
parallelism vs concurrency
Concurrency existence of multiple threads of execution
goal of concurrency is to prevent thread starvation
concurrency is required operationally
Parallelism concurrent threads execute at the same time on multiple cores
parallelism is only about throughput
It is an optimization, not a functional requirement
![Page 3: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/3.jpg)
Limitations to linear speedup of parallel code
Serial code
Overhead from parallelization
Synchronization
Sequential input/output
![Page 4: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/4.jpg)
Parallel Speedup Calculation
Amdahl’s Law:
Gustafson’s Law: - 0n
![Page 5: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/5.jpg)
Phases of parallel development
Finding Concurrency Task Decomposition pattern
Data Decomposition pattern
Group Tasks Pattern
Order Tasks Pattern
Data Sharing pattern
Algorithm Structures
Support Structures
Implementation Mechanisms
![Page 6: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/6.jpg)
The Algorithm Structure Pattern
Task Parallelism Pattern
Divide and Conquer Pattern
Geometric Decomposition Pattern
Recursive Data Pattern
Pipeline Pattern
![Page 7: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/7.jpg)
The Supporting Structures Pattern
SPMD (Single Program/Multiple Data)
Master/Worker
Loop Parallelism
Fork/Join
![Page 8: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/8.jpg)
Data Parallelism
Search for Loops
Unroll Sequential Loops
Evaluating Performance Considerations: Conduct performance benchmarks to confirm potential performance
improvements
When there is minimal or no performance gain, one solution is to change the chunk size
Parallel.For and Parallel.ForEach ParallelLoopState for breaking
![Page 9: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/9.jpg)
Reduction/Aggregation
![Page 10: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/10.jpg)
Variations of Reduce
Scan pattern - each iteration of a loop depends on data computed in the previous iteration.
Pack pattern - uses a parallel loop to select elements to retain or discard => The result is a subset of the original input.
Map Reduce
![Page 11: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/11.jpg)
MapReduce Pattern
Elements:
1) input - a collection of key and value pairs;
2) intermediate collection - a non-unique collection of key and value pairs;
3) third collection - a reduction of the non-unique keys from the intermediate collection.
![Page 12: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/12.jpg)
MapReduce Example
Counting Words across multiple documents
![Page 13: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/13.jpg)
Map/reduce via PLINQ
![Page 14: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/14.jpg)
Futures
Future is a stand-in for a computational result that is initially unknown but becomes available at a later time.
A future in .NET is a Task<TResult> that returns a value.
A .NET continuation task is a task that automatically starts when other tasks, known as its antecedents, complete.
![Page 15: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/15.jpg)
Futures example
![Page 16: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/16.jpg)
Dynamic Task Parallelism
Dynamic Tasks (decomposition or “divide and conquer”) - tasks that are dynamically added to the work queue as the computation proceeds.
Most known instance – recursion.
![Page 17: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/17.jpg)
Dynamic Task example
![Page 18: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/18.jpg)
Pipelines
Each task implements a stage of the pipeline, and the queues act as buffers that allow the stages of the pipeline to execute concurrently, even though the values are processed in order.
The buffers BlockingCollection<T>
![Page 19: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/19.jpg)
Pipeline example
![Page 20: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/20.jpg)
C# 5 : async and await
asynchronous pattern,
event-based asynchronous pattern,
task-based asynchronous pattern (TAP) : async&await!
![Page 21: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/21.jpg)
Asynchronous Pattern
![Page 22: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/22.jpg)
Event-Based Asynchronous Pattern
![Page 23: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/23.jpg)
Task-Based Asynchronous Pattern
![Page 24: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/24.jpg)
Using Multiple Asynchronous Methods
Using Multiple Asynchronous Methods:
vs
Using Combinators:
![Page 25: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/25.jpg)
Converting the Asynchronous Pattern
The TaskFactory class defines the FromAsync method that allows converting methods using the asynchronous pattern to the TAP.
![Page 26: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/26.jpg)
ERROR HANDLING
![Page 27: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/27.jpg)
Multiple tasks error handling
![Page 28: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/28.jpg)
CANCELLATION
Cancellation with Framework Features
![Page 29: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/29.jpg)
CANCELLATION
Cancellation with custom tasks
![Page 30: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/30.jpg)
Literature Concurrent Programming on Windows
“MapReduce: Simplified Data Processing on Large Clusters” by Jeffrey Dean and Sanjay Ghemawat. 2004
Parallel Programming with Microsoft Visual Studio 2010 Step by Step
Parallel Programming with Microsoft®.NET: Design Patterns for Decomposition and Coordination on Multicore Architectures
Pro .NET 4 Parallel Programming in C# [Adam_Freeman]
Professional Parallel Programming with C# [Gaston_Hillar]
Professional Parallel Programming with C# Master Parallel Extensions with NET 4
.NET 4.5 Parallel Extensions Cookbook | Packt Publishing
![Page 31: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/31.jpg)
Questions?
Parallel programming in modern world .NET technics
![Page 32: Parallel programming in modern world .net technics shared](https://reader036.vdocuments.us/reader036/viewer/2022062513/554f87dab4c905435d8b4cc2/html5/thumbnails/32.jpg)
Thanks!