Presentation is loading. Please wait.

Presentation is loading. Please wait.

FUTURE OF.NET PARALLEL PROGRAMMING Joseph Albahari SESSION CODE: DEV308 (c) 2011 Microsoft. All rights reserved.

Similar presentations


Presentation on theme: "FUTURE OF.NET PARALLEL PROGRAMMING Joseph Albahari SESSION CODE: DEV308 (c) 2011 Microsoft. All rights reserved."— Presentation transcript:

1

2 FUTURE OF.NET PARALLEL PROGRAMMING Joseph Albahari SESSION CODE: DEV308 (c) 2011 Microsoft. All rights reserved.

3 JOE ALBAHARI (c) 2011 Microsoft. All rights reserved.

4 Agenda ► Parallel Programming in Framework 4.0 recap ► TPL Dataflow in vNext (c) 2011 Microsoft. All rights reserved.

5 CPU Clock Speeds over Past 25 Years (c) 2011 Microsoft. All rights reserved. (logarithmic)

6 (c) 2011 Microsoft. All rights reserved. Intel’s 80-core prototype

7 Parallel APIs in Framework 4.0 (c) 2011 Microsoft. All rights reserved. Tasks Parallel Loops PLINQ Concurrent Collections CLR Thread Pool

8 Fork/Join (c) 2011 Microsoft. All rights reserved. Fork Join

9 Parallel Programming APIs APIForkJoin PLINQ Parallel Loops Task Parallelism (c) 2011 Microsoft. All rights reserved. Functional Imperative Task Parallel Library (TPL)

10 Task vs. Data Parallelism (c) 2011 Microsoft. All rights reserved. Tasks Data T1T2T3T4 T1T2T3T4 Parallel Loops PLINQ

11 ► Highest-level parallel API ► Data parallelism ► Declarative ► Transparently parallelizes LINQ queries (c) 2011 Microsoft. All rights reserved.

12 string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" }; var query = from n in names where n.Contains ("a") orderby n.Length select n.ToUpper(); string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" }; var query = names.Where (n => n.Contains ("a")).OrderBy (n => n.Length).Select (n => n.ToUpper());

13

14

15 PLINQ – gotchas ► Query needs ‘meat’ ► Original ordering lost (by default) ► Functional impurity can break queries ► No work-stealing with range partitioning (c) 2011 Microsoft. All rights reserved.

16 Math.Sqrt (numbers.Average (n => n * n)) Root-mean-square double mean = numbers.Average(); double sdev = Math.Sqrt (numbers.Average (n => { double dif = n - mean; return dif * dif; })); Standard deviation var numbers = new[] { 2, 3, 4, 5, 6 }.AsParallel(); var numbers = new[] { 2, 3, 4, 5, 6 }.AsParallel();

17 PLINQ – Tricks & Tips ► Can do I/O bound queries – but there are better ways ►.ForAll() defeats data collation ► Aggregations are parallelizable albahari.com/threading (c) 2011 Microsoft. All rights reserved.

18 Parallel Loops (c) 2011 Microsoft. All rights reserved. Tasks Parallel Loops PLINQ Concurrent Collections CLR Thread Pool

19 Parallel Loops Parallel.For Parallel.ForEach (c) 2011 Microsoft. All rights reserved.

20 Parallel.For (1, 1000, i => Foo (i) ); Parallel.For (1, 1000, i => Foo (i) ); for (int i = 1; i < 1000; i++) Foo (i); for (int i = 1; i < 1000; i++) Foo (i); Sequential Parallel

21 var toTest = new TypeToTest(); var methodsToTest = from m in toTest.GetType().GetMethods() where m.GetCustomAttributes (false).OfType ().Any() select m; Parallel.ForEach (methodsToTest, m => { try { m.Invoke (instanceToTest, null)); } catch (Exception ex) {... } } Parallel Unit Testing (c) 2011 Microsoft. All rights reserved.

22 Tricks & Tips ► Best with moderately sized work items – 1µs to 100ms ► Avoid for I/O bound work ► Parallel.For = range partitioning + work stealing (c) 2011 Microsoft. All rights reserved.

23 Task Parallelism (c) 2011 Microsoft. All rights reserved. Tasks Parallel Loops PLINQ Concurrent Collections CLR Thread Pool

24 Task Parallelism ►Parallel.Invoke(Action[] actions) ► Task / Task (c) 2011 Microsoft. All rights reserved.

25 Task and Task A task represents a concurrent operation (c) 2011 Microsoft. All rights reserved.

26 Tasks have two purposes 1.For multithreading – Including Parallel programming – Gets you into the thread pool 2.A value-added signaling construct – I/O bound – Asynchronous Pattern (c) 2011 Microsoft. All rights reserved. Task TaskScheduler TaskCompletionSource Task.Factory.StartNew() new TaskCompletionSource<>()

27 Tasks: Tricks and Tips ► Be careful with continuations – Consider async CTP if you need them – Conditional continuations are particularly nasty ► Exception-handle ‘set-and-forget’ tasks (c) 2011 Microsoft. All rights reserved.

28 MANDELBROT DEMO (c) 2011 Microsoft. All rights reserved.

29 TPL Dataflow CTP (c) 2011 Microsoft. All rights reserved. Tasks Parallel Loops PLINQ Concurrent Collections CLR Thread Pool Dataflow

30 TPL Dataflow ► High throughput, low-latency scenarios ► Typical applications: – Manufacturing – Imaging – Biology – Oil & Gas – Finance – Robotics (c) 2011 Microsoft. All rights reserved.

31 TPL Dataflow AAL (C++) CCR (MS Robotics) Axum

32

33

34

35 Dataflow Blocks BufferingExecutionJoining BufferBlock BroadcastBlock WriteOnceBlock ActionBlock TransformBlock TransformManyBlock BatchBlock JoinBlock BatchedJoinBlock (c) 2011 Microsoft. All rights reserved.

36 ActionBlock (c) 2011 Microsoft. All rights reserved. Action delegate

37 ActionBlock (c) 2011 Microsoft. All rights reserved.

38 Multiple Blocks (c) 2011 Microsoft. All rights reserved. Action

39 MaxDegreeOfParallelism (c) 2011 Microsoft. All rights reserved. MaxDegreeOfParallelism = 2

40 TransformBlock (c) 2011 Microsoft. All rights reserved. Func

41 TransformManyBlock (c) 2011 Microsoft. All rights reserved. Func

42 TransformBlock + ActionBlock (c) 2011 Microsoft. All rights reserved. Func Action<>

43 Mandelbrot Pipeline (c) 2011 Microsoft. All rights reserved. Func Action Render Encode Save

44 Dataflow Blocks BufferingExecutionJoining BufferBlock BroadcastBlock WriteOnceBlock ActionBlock TransformBlock TransformManyBlock BatchBlock JoinBlock BatchedJoinBlock (c) 2011 Microsoft. All rights reserved.

45 BatchBlock<> (c) 2011 Microsoft. All rights reserved.

46 JoinBlock<> (c) 2011 Microsoft. All rights reserved.

47 Joining Blocks: Greedy by default (c) 2011 Microsoft. All rights reserved.

48 Non-greedy (c) 2011 Microsoft. All rights reserved.

49 DataFlow Blocks BufferingExecutionJoining BufferBlock BroadcastBlock WriteOnceBlock ActionBlock TransformBlock TransformManyBlock BatchBlock JoinBlock BatchedJoinBlock (c) 2011 Microsoft. All rights reserved.

50 BufferBlock<> (c) 2011 Microsoft. All rights reserved.

51 BroadcastBlock<> (c) 2011 Microsoft. All rights reserved. “overwrite buffer”

52 WriteOnceBlock<> (c) 2011 Microsoft. All rights reserved.

53 Dataflow Blocks BufferingExecutionJoining BufferBlock BroadcastBlock WriteOnceBlock ActionBlock TransformBlock TransformManyBlock BatchBlock JoinBlock BatchedJoinBlock (c) 2011 Microsoft. All rights reserved.

54 Extensibility & Interoperability ► Custom data blocks ► Rx: – AsObservable() – AsObserver() (c) 2011 Microsoft. All rights reserved.

55 Enrol in Microsoft Virtual Academy Today Why Enroll, other than it being free? The MVA helps improve your IT skill set and advance your career with a free, easy to access training portal that allows you to learn at your own pace, focusing on Microsoft technologies. What Do I get for enrolment? ► Free training to make you become the Cloud-Hero in my Organization ► Help mastering your Training Path and get the recognition ► Connect with other IT Pros and discuss The Cloud Where do I Enrol? Then tell us what you think.

56 © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. (c) 2011 Microsoft. All rights reserved.


Download ppt "FUTURE OF.NET PARALLEL PROGRAMMING Joseph Albahari SESSION CODE: DEV308 (c) 2011 Microsoft. All rights reserved."

Similar presentations


Ads by Google