SlideShare ist ein Scribd-Unternehmen logo
1 von 41
http://go.microsoft.com/?linkid=9692084
Parallel Programming with Visual Studio 2010 and the .NET Framework 4 Stephen Toub Microsoft Corporation October 2009
Agenda Why Parallelism, Why Now? Difficulties w/ Visual Studio 2008 & .NET 3.5 Solutions w/ Visual Studio 2010 & .NET 4 Parallel LINQ Task Parallel Library New Coordination & Synchronization Primitives New Parallel Debugger Windows New Profiler Concurrency Visualizations
Moore’s Law “The number of transistors incorporated in a chip will approximately double every 24 months.”  Gordon Moore Intel Co-Founder http://www.intel.com/pressroom/kits/events/moores_law_40th/
Moore’s Law: Alive and Well? The number of transistors doubles every two years… More than 1 billiontransistors in 2006! http://upload.wikimedia.org/wikipedia/commons/2/25/Transistor_Count_and_Moore%27s_Law_-_2008_1024.png
Moore’s Law: Feel the Heat!  Sun’s Surface 10,000 1,000 100 10 1 Rocket Nozzle Nuclear Reactor Power Density (W/cm2) Pentium® processors Hot Plate 8080 ‘70	                  ‘80	                ’90             ’00                    ‘10 486 386 Intel Developer Forum, Spring 2004 - Pat Gelsinger
Moore’s Law: But Different Frequencies will NOT get much faster! Maybe 5 to 10% every year or so, a few more times… And these modest gains would make the chips A LOThotter! http://www.tomshw.it/cpu.php?guide=20051121
The Manycore Shift “[A]fter decades of single core processors, the high volume processor industry has gone from single to dual to quad-core in just the last two years. Moore’s Law scaling should easily let us hit the 80-core mark in mainstream processors within the next ten years and quite possibly even less.”-- Justin Rattner, CTO, Intel (February 2007) “If you haven’t done so already, now is the time to take a hard look at the design of your application, determine what operations are CPU-sensitive now or are likely to become so soon, and identify how those places could benefit from concurrency.”-- Herb Sutter, C++ Architect at Microsoft (March 2005)
I'm convinced… now what? Multithreaded programming is “hard” today Doable by only a subgroup of senior specialists Parallel patterns are not prevalent, well known, nor easy to implement So many potential problems Businesses have little desire to “go deep” Best devs should focus on business value, not concurrency Need simple ways to allow all devs to write concurrent code
Example: “Race Car Drivers” IEnumerable<RaceCarDriver> drivers = ...; varresults = new List<RaceCarDriver>(); foreach(var driver in drivers) { if (driver.Name == queryName && driver.Wins.Count >= queryWinCount)     { results.Add(driver);     } } results.Sort((b1, b2) =>      b1.Age.CompareTo(b2.Age));
Manual Parallel Solution IEnumerable<RaceCarDriver> drivers = …; varresults = new List<RaceCarDriver>(); intpartitionsCount = Environment.ProcessorCount; intremainingCount = partitionsCount; varenumerator = drivers.GetEnumerator(); try { using (vardone = new ManualResetEvent(false)) { for(inti = 0; i < partitionsCount; i++) { ThreadPool.QueueUserWorkItem(delegate { while(true) { RaceCarDriver driver; lock (enumerator) { if (!enumerator.MoveNext()) break;                         driver = enumerator.Current;                     } if (driver.Name == queryName && driver.Wins.Count >= queryWinCount) { lock(results) results.Add(driver);                     }                 } if (Interlocked.Decrement(refremainingCount) == 0) done.Set();             });         } done.WaitOne(); results.Sort((b1, b2) => b1.Age.CompareTo(b2.Age));     } } finally { if (enumerator is IDisposable) ((IDisposable)enumerator).Dispose(); }
P LINQ Solution .AsParallel() varresults = from driver in drivers where driver.Name == queryName && driver.Wins.Count >= queryWinCount orderbydriver.Ageascending select driver;
Visual Studio 2010Tools, Programming Models, Runtimes Programming Models Tools .NET Framework 4 Visual C++ 10 Visual  Studio IDE Parallel LINQ Parallel Pattern Library Parallel Debugger Tool Windows AgentsLibrary Task Parallel  Library Data Structures Data Structures Concurrency Runtime Profiler Concurrency Analysis Task Scheduler ThreadPool Task Scheduler Resource Manager Resource Manager Operating System Windows Threads UMS Threads Key: Managed Native Tooling
Parallel Extensions What is it? Pure .NET libraries No compiler changes necessary mscorlib.dll, System.dll, System.Core.dll Lightweight, user-mode runtime Key ThreadPool enhancements Supports imperative and declarative, data and task parallelism Declarative data parallelism (PLINQ) Imperative data and task parallelism (Task Parallel Library) New coordination/synchronization constructs Why do we need it? Supports parallelism in any .NET language Delivers reduced concept count and complexity, better time to solution Begins to move parallelism capabilities from concurrency experts to domain experts How do we get it? Built into the core of .NET 4 Debugging and profiling support in Visual Studio 2010
Architecture PLINQ Execution Engine .NET Program Parallel Algorithms Declarative Queries Query Analysis Data Partitioning Chunk Range Hash Striped Repartitioning Custom Operator Types Merging Sync and Async Order Preserving Buffered Inverted Map Filter Sort Search Reduce Group Join … C# Compiler VB Compiler Task Parallel Library Coordination Data Structures C++ Compiler Loop replacementsImperative Task Parallelism Scheduling Thread-safe Collections Synchronization Types Coordination Types F# Compiler Other .NET Compiler Threads IL Proc 1 Proc p …
Language Integrated Query (LINQ) LINQ enabled data sources Others… C# Visual Basic .NET Standard Query Operators LINQ-enabled ADO.NET LINQ To SQL LINQ To XML LINQ To Objects LINQ To Datasets LINQ To Entities <book>     <title/>     <author/>     <price/> </book> Relational Objects XML
Writing a LINQ-to-Objects Query Two ways to write queries Comprehensions Syntax extensions to C# and Visual Basic APIs Used as extension methods on IEnumerable<T> System.Linq.Enumerable class Compiler converts the former into the latter API implementation does the actual work var q = from x in Y where p(x) orderby x.f1select x.f2; var q = Y.Where(x => p(x)).OrderBy(x => x.f1).Select(x => x.f2); var q = Enumerable.Select( Enumerable.OrderBy( Enumerable.Where(Y, x => p(x)), x => x.f1), x => x.f2);
LINQ Query Operators ,[object Object],Aggregate(3) All(1) Any(2) AsEnumerable(1) Average(20) Cast(1) Concat(1) Contains(2) Count(2) DefaultIfEmpty(2) Distinct(2) ElementAt(1) ElementAtOrDefault(1) Empty(1) Except(2) First(2) FirstOrDefault(2) GroupBy(8) GroupJoin(2) Intersect(2) Join(2) Last(2) LastOrDefault(2) LongCount(2) Max(22) Min(22) OfType(1) OrderBy(2) OrderByDescending(2) Range(1) Repeat(1) Reverse(1) Select(2) SelectMany(4) SequenceEqual(2) Single(2) SingleOrDefault(2) Skip(1) SkipWhile(2) Sum(20) Take(1) TakeWhile(2) ThenBy(2) ThenByDescending(2) ToArray(1) ToDictionary(4) ToList(1) ToLookup(4) Union(2) Where(2) Zip(1) var operators = from method in typeof(Enumerable).GetMethods( BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)                 group method by method.Name into methods orderbymethods.Key                 select new { Name = methods.Key, Count=methods.Count() };
Query Operators, cont. Tree of operators Producers No input Examples: Range, Repeat Consumer/producers Transform input stream(s) into output stream Examples: Select, Where, Join, Skip, Take Consumers Reduce to a single value Examples: Aggregate, Min, Max, First Many are unary while others are binary ,[object Object],… Select Join Where Where
Implementation of a Query Operator What might an implementation look like? Does it have to be this way? What if we could do this in… parallel?! public static IEnumerable<TSource> Where<TSource>(     this IEnumerable<TSource> source,  Func<TSource, bool> predicate) {     if (source == null || predicate == null)          throw new ArgumentNullException(); foreach (var item in source)     {         if (predicate(item)) yield return item;     } } public static IEnumerable<TSource> Where<TSource>(     this IEnumerable<TSource> source,  Func<TSource, bool> predicate) {     ... }
Parallel LINQ (PLINQ) Utilizes parallel hardware for LINQ queries Abstracts away most parallelism details Partitions and merges data intelligently Supports all .NET Standard Query Operators Plus a few knobs Works for any IEnumerable<T> Optimizations for other types (T[], IList<T>) Supports custom partitioning (Partitioner<T>) Built on top of the rest of Parallel Extensions
Programming Model Minimal impact to existing LINQ programming model AsParallel extension method ParallelEnumerable class Implements the Standard Query Operators, but for ParallelQuery<T> public static ParallelQuery<T>  AsParallel<T>(this IEnumerable<T> source); public static ParallelQuery<TSource>  Where<TSource>(    this ParallelQuery<TSource> source,  Func<TSource, bool> predicate)
Writing a PLINQ Query Two ways to write queries Comprehensions Syntax extensions to C# and Visual Basic APIs Used as extension methods on ParallelQuery<T> System.Linq.ParallelEnumerable class Compiler converts the former into the latter  As with serial LINQ, API implementation does the actual work var q = from x in Y.AsParallel()where p(x) orderby x.f1select x.f2; var q = Y.AsParallel().Where(x => p(x)).OrderBy(x => x.f1).Select(x => x.f2); var q = ParallelEnumerable.Select( ParallelEnumerable.OrderBy( ParallelEnumerable.Where(Y.AsParallel(), x => p(x)), x => x.f1), x => x.f2);
PLINQ Knobs Additional Extension Methods WithDegreeOfParallelism AsOrdered WithCancellation WithMergeOptions WithExecutionMode var results = from driver in drivers.AsParallel().WithDegreeOfParallelism(4)               where driver.Name == queryName && driver.Wins.Count >= queryWinCount orderbydriver.Age ascending               select driver; var results = from driver in drivers.AsParallel().AsOrdered()               where driver.Name == queryName && driver.Wins.Count >= queryWinCount orderbydriver.Age ascending               select driver;
Partitioning ,[object Object]
Operators are replicated across the partitions
Example	from x in A where p(x) … ,[object Object],… Task 1 … where p(x) A … Tasks 2..n-1 … … Task n… where p(x)
Partitioning: Load Balancing DynamicScheduling Static Scheduling (Range) CPU0 CPU1 … CPUN CPU0 CPU1 … CPUN 5 5 7 3 1 7 3 1 6 6 8 8 2 2 4 4
Several partitioning schemes built-in Chunk Works with any IEnumerable<T> Single enumerator shared; chunks handed out on-demand Range Works only with IList<T> Input divided into contiguous regions, one per partition Stripe Works only with IList<T> Elements handed out round-robin to each partition Hash Works with any IEnumerable<T> Elements assigned to partition based on hash code Custom partitioning available through Partitioner<T> Partitioner.Createavailable for tighter control over built-in partitioning schemes Partitioning: Algorithms
Operator Fusion ,[object Object]
Example: (from x in D.AsParallel() where p(x) select x*x*x).Sum();
Partition and merge mean synchronization => scalabilitybottleneck
Instead, we can fuse operators together:
Minimizes number of partitioning/merging steps necessary… Task 1 … … Task 1 … … Task 1 … where p(x) select x3 Sum() D # … Task n… … Task n… … Task n… where p(x) select x3 Sum() … Task 1 … where p(x) select x3 Sum() D # … Task n… where p(x) select x3 Sum()
Merging Pipelined: separate consumer thread Default for GetEnumerator() And hence foreach loops AutoBuffered, NoBuffering Access to data as its available But more synchronization overhead Stop-and-go: consumer helps Sorts, ToArray, ToList, etc. FullyBuffered Minimizes context switches But higher latency and more memory Inverted: no merging needed ForAll extension method Most efficient by far But not always applicable Requires side-effects Thread 2 Thread 1 Thread 1 Thread 3 Thread 4 Thread 1 Thread 1 Thread 1 Thread 2 Thread 3 Thread 1 Thread 1 Thread 1 Thread 2 Thread 3
Parallelism Blockers Ordering not guaranteed Exceptions Thread affinity Operations with < 1.0 speedup Side effects and mutability are serious issues Most queries do not use side effects, but it’s possible… int[] values = new int[] { 0, 1, 2 };var q = from x in values.AsParallel() select x * 2;int[] scaled = q.ToArray(); // == { 0, 2, 4 }? System.AggregateException object[] data = new object[] { "foo", null, null };var q = from x in data.AsParallel() select o.ToString(); controls.AsParallel().ForAll(c => c.Size = ...); IEnumerable<int> input = …; var doubled = from x in input.AsParallel() select x*2; Random rand = new Random(); var q = from i in Enumerable.Range(0, 10000).AsParallel()         select rand.Next();
Task Parallel LibraryLoops Loops are a common source of work Can be parallelized when iterations are independent Body doesn’t depend on mutable state / synchronization used Synchronous All iterations finish, regularly or exceptionally Lots of knobs Breaking, task-local state, custom partitioning, cancellation, scheduling, degree of parallelism Visual Studio 2010 profiler support (as with PLINQ) for (inti = 0; i < n; i++) work(i); … foreach (T e in data) work(e); Parallel.For(0, n, i => work(i)); … Parallel.ForEach(data, e => work(e));
Task Parallel LibraryStatements Sequence of statements When independent, can be parallelized Synchronous (same as loops) Under the covers May use Parallel.For, may use Tasks StatementA(); StatementB; StatementC(); Parallel.Invoke(   () => StatementA() ,   () => StatementB   ,   () => StatementC() );
Task Parallel LibraryTasks System.Threading.Tasks Task Represents an asynchronous operation Supports waiting, cancellation, continuations, … Parent/child relationships 1st-class debugging support in Visual Studio 2010 Task<TResult> : Task Tasks that return results TaskCompletionSource<TResult> Create Task<TResult>s to represent other operations TaskScheduler Represents a scheduler that executes tasks Extensible TaskScheduler.Default => ThreadPool
Global Queue Worker Thread 1 Worker Thread 1 ThreadPool in .NET 3.5 … Item 4 Item 5 Program Thread Item 1 Item 2 Item 3 Item 6 Thread Management: ,[object Object]
Idle Thread Retirement,[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk Ganesh Samarthyam
 
Property-based Testing and Generators (Lua)
Property-based Testing and Generators (Lua)Property-based Testing and Generators (Lua)
Property-based Testing and Generators (Lua)Sumant Tambe
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherBlue Elephant Consulting
 
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDSOverloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDSSumant Tambe
 
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...Citus Data
 
Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Databricks
 
Big-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbaiBig-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbaiUnmesh Baile
 
Reactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxReactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxSumant Tambe
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Richard Thomson
 
Scaling with apache spark (a lesson in unintended consequences) strange loo...
Scaling with apache spark (a lesson in unintended consequences)   strange loo...Scaling with apache spark (a lesson in unintended consequences)   strange loo...
Scaling with apache spark (a lesson in unintended consequences) strange loo...Holden Karau
 
Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016MLconf
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMSfawzmasood
 
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark... Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...Databricks
 
Holden Karau - Spark ML for Custom Models
Holden Karau - Spark ML for Custom ModelsHolden Karau - Spark ML for Custom Models
Holden Karau - Spark ML for Custom Modelssparktc
 
Understanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterUnderstanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterIhsan Fauzi Rahman
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Ravi Okade
 

Was ist angesagt? (20)

Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
 
Property-based Testing and Generators (Lua)
Property-based Testing and Generators (Lua)Property-based Testing and Generators (Lua)
Property-based Testing and Generators (Lua)
 
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each OtherIntro To C++ - Class #17: Pointers!, Objects Talking To Each Other
Intro To C++ - Class #17: Pointers!, Objects Talking To Each Other
 
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDSOverloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
Overloading in Overdrive: A Generic Data-Centric Messaging Library for DDS
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
 
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
Tutorial: Implementing your first Postgres extension | PGConf EU 2019 | Burak...
 
Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...Ge aviation spark application experience porting analytics into py spark ml p...
Ge aviation spark application experience porting analytics into py spark ml p...
 
Big-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbaiBig-data-analysis-training-in-mumbai
Big-data-analysis-training-in-mumbai
 
Reactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxReactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and Rx
 
Idiomatic C++
Idiomatic C++Idiomatic C++
Idiomatic C++
 
Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++Consuming and Creating Libraries in C++
Consuming and Creating Libraries in C++
 
Scaling with apache spark (a lesson in unintended consequences) strange loo...
Scaling with apache spark (a lesson in unintended consequences)   strange loo...Scaling with apache spark (a lesson in unintended consequences)   strange loo...
Scaling with apache spark (a lesson in unintended consequences) strange loo...
 
Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016Kaz Sato, Evangelist, Google at MLconf ATL 2016
Kaz Sato, Evangelist, Google at MLconf ATL 2016
 
STL ALGORITHMS
STL ALGORITHMSSTL ALGORITHMS
STL ALGORITHMS
 
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark... Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
 
Numba lightning
Numba lightningNumba lightning
Numba lightning
 
Linq intro
Linq introLinq intro
Linq intro
 
Holden Karau - Spark ML for Custom Models
Holden Karau - Spark ML for Custom ModelsHolden Karau - Spark ML for Custom Models
Holden Karau - Spark ML for Custom Models
 
Understanding Javascript Engine to Code Better
Understanding Javascript Engine to Code BetterUnderstanding Javascript Engine to Code Better
Understanding Javascript Engine to Code Better
 
Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)Optimizing Application Architecture (.NET/Java topics)
Optimizing Application Architecture (.NET/Java topics)
 

Andere mochten auch

Announcements, 10/28/12
Announcements, 10/28/12Announcements, 10/28/12
Announcements, 10/28/12CLADSM
 
melssCRM Case Study - CMO Axis
melssCRM Case Study - CMO AxismelssCRM Case Study - CMO Axis
melssCRM Case Study - CMO AxismelssCRM
 
Parents’ workshop lp without videos attached
Parents’ workshop lp   without videos attachedParents’ workshop lp   without videos attached
Parents’ workshop lp without videos attachedPakLiam
 
Quality Teaching - Fabrice Hénard
Quality Teaching - Fabrice HénardQuality Teaching - Fabrice Hénard
Quality Teaching - Fabrice HénardEduSkills OECD
 
Announcements, 1/20/13
Announcements, 1/20/13Announcements, 1/20/13
Announcements, 1/20/13CLADSM
 
Announcements, 8/11/13
Announcements, 8/11/13Announcements, 8/11/13
Announcements, 8/11/13CLADSM
 
búsqueda en google
búsqueda en googlebúsqueda en google
búsqueda en googleMiranda HrMr
 
FAITH That Welcomes God's Purpose Slides, 9/5/10
FAITH That Welcomes God's Purpose Slides, 9/5/10FAITH That Welcomes God's Purpose Slides, 9/5/10
FAITH That Welcomes God's Purpose Slides, 9/5/10CLADSM
 
Of First Importance Slides, 4/29/12
Of First Importance Slides, 4/29/12Of First Importance Slides, 4/29/12
Of First Importance Slides, 4/29/12CLADSM
 
一般社団法人 ジャパンショッピングツーリズム協会(JSTO)
一般社団法人 ジャパンショッピングツーリズム協会(JSTO)一般社団法人 ジャパンショッピングツーリズム協会(JSTO)
一般社団法人 ジャパンショッピングツーリズム協会(JSTO)Unreasonable Lab Japan
 
Announcements, 10/23/11
Announcements, 10/23/11Announcements, 10/23/11
Announcements, 10/23/11CLADSM
 
Tranformational Model of Translational Research that Leverages Educational Te...
Tranformational Model of Translational Research that Leverages Educational Te...Tranformational Model of Translational Research that Leverages Educational Te...
Tranformational Model of Translational Research that Leverages Educational Te...EduSkills OECD
 
Announcements, 8/10/14
Announcements, 8/10/14Announcements, 8/10/14
Announcements, 8/10/14CLADSM
 
Announcements, 10/20/13
Announcements, 10/20/13Announcements, 10/20/13
Announcements, 10/20/13CLADSM
 
Noah's Faith WORKED Slides, 8/1/10
Noah's Faith WORKED Slides, 8/1/10Noah's Faith WORKED Slides, 8/1/10
Noah's Faith WORKED Slides, 8/1/10CLADSM
 
Faith That WAITS On God Slides, 8/15/10
Faith That WAITS On God Slides, 8/15/10Faith That WAITS On God Slides, 8/15/10
Faith That WAITS On God Slides, 8/15/10CLADSM
 

Andere mochten auch (20)

Uu 25 92 Tentang Perkoperasian
Uu 25 92 Tentang PerkoperasianUu 25 92 Tentang Perkoperasian
Uu 25 92 Tentang Perkoperasian
 
Announcements, 10/28/12
Announcements, 10/28/12Announcements, 10/28/12
Announcements, 10/28/12
 
melssCRM Case Study - CMO Axis
melssCRM Case Study - CMO AxismelssCRM Case Study - CMO Axis
melssCRM Case Study - CMO Axis
 
Parents’ workshop lp without videos attached
Parents’ workshop lp   without videos attachedParents’ workshop lp   without videos attached
Parents’ workshop lp without videos attached
 
Quality Teaching - Fabrice Hénard
Quality Teaching - Fabrice HénardQuality Teaching - Fabrice Hénard
Quality Teaching - Fabrice Hénard
 
Announcements, 1/20/13
Announcements, 1/20/13Announcements, 1/20/13
Announcements, 1/20/13
 
Announcements, 8/11/13
Announcements, 8/11/13Announcements, 8/11/13
Announcements, 8/11/13
 
búsqueda en google
búsqueda en googlebúsqueda en google
búsqueda en google
 
FAITH That Welcomes God's Purpose Slides, 9/5/10
FAITH That Welcomes God's Purpose Slides, 9/5/10FAITH That Welcomes God's Purpose Slides, 9/5/10
FAITH That Welcomes God's Purpose Slides, 9/5/10
 
Of First Importance Slides, 4/29/12
Of First Importance Slides, 4/29/12Of First Importance Slides, 4/29/12
Of First Importance Slides, 4/29/12
 
Neadus callus fire & security ltd
Neadus callus fire & security ltdNeadus callus fire & security ltd
Neadus callus fire & security ltd
 
一般社団法人 ジャパンショッピングツーリズム協会(JSTO)
一般社団法人 ジャパンショッピングツーリズム協会(JSTO)一般社団法人 ジャパンショッピングツーリズム協会(JSTO)
一般社団法人 ジャパンショッピングツーリズム協会(JSTO)
 
Announcements, 10/23/11
Announcements, 10/23/11Announcements, 10/23/11
Announcements, 10/23/11
 
Springer link
Springer linkSpringer link
Springer link
 
Tranformational Model of Translational Research that Leverages Educational Te...
Tranformational Model of Translational Research that Leverages Educational Te...Tranformational Model of Translational Research that Leverages Educational Te...
Tranformational Model of Translational Research that Leverages Educational Te...
 
Announcements, 8/10/14
Announcements, 8/10/14Announcements, 8/10/14
Announcements, 8/10/14
 
Announcements, 10/20/13
Announcements, 10/20/13Announcements, 10/20/13
Announcements, 10/20/13
 
Noah's Faith WORKED Slides, 8/1/10
Noah's Faith WORKED Slides, 8/1/10Noah's Faith WORKED Slides, 8/1/10
Noah's Faith WORKED Slides, 8/1/10
 
Faith That WAITS On God Slides, 8/15/10
Faith That WAITS On God Slides, 8/15/10Faith That WAITS On God Slides, 8/15/10
Faith That WAITS On God Slides, 8/15/10
 
Permensosri 111/HUK/2009
Permensosri 111/HUK/2009Permensosri 111/HUK/2009
Permensosri 111/HUK/2009
 

Ähnlich wie Toub parallelism tour_oct2009

Parallel Extentions to the .NET Framework
Parallel Extentions to the .NET FrameworkParallel Extentions to the .NET Framework
Parallel Extentions to the .NET Frameworkukdpe
 
MTaulty_DevWeek_Parallel
MTaulty_DevWeek_ParallelMTaulty_DevWeek_Parallel
MTaulty_DevWeek_Parallelukdpe
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#Talbott Crowell
 
Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0Bruce Johnson
 
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersMSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersDave Bost
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Pythongturnquist
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overviewbwullems
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software PerformanceGibraltar Software
 
SharePoint for the .NET Developer
SharePoint for the .NET DeveloperSharePoint for the .NET Developer
SharePoint for the .NET DeveloperJohn Calvert
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeDmitri Nesteruk
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkCodeOps Technologies LLP
 
GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...
GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...
GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...James Anderson
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...Maarten Balliauw
 
Expanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerExpanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerCisco Canada
 
Ztech Connect '19, IBM PureApplication
Ztech Connect '19, IBM PureApplicationZtech Connect '19, IBM PureApplication
Ztech Connect '19, IBM PureApplicationChris Clark
 
Parallel Computing For Managed Developers
Parallel Computing For Managed DevelopersParallel Computing For Managed Developers
Parallel Computing For Managed DevelopersBala Subra
 

Ähnlich wie Toub parallelism tour_oct2009 (20)

Parallel Extentions to the .NET Framework
Parallel Extentions to the .NET FrameworkParallel Extentions to the .NET Framework
Parallel Extentions to the .NET Framework
 
Using Parallel Computing Platform - NHDNUG
Using Parallel Computing Platform - NHDNUGUsing Parallel Computing Platform - NHDNUG
Using Parallel Computing Platform - NHDNUG
 
MTaulty_DevWeek_Parallel
MTaulty_DevWeek_ParallelMTaulty_DevWeek_Parallel
MTaulty_DevWeek_Parallel
 
Exploring SharePoint with F#
Exploring SharePoint with F#Exploring SharePoint with F#
Exploring SharePoint with F#
 
Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0Overview of VS2010 and .NET 4.0
Overview of VS2010 and .NET 4.0
 
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersMSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
 
Flink internals web
Flink internals web Flink internals web
Flink internals web
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overview
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
Natural Laws of Software Performance
Natural Laws of Software PerformanceNatural Laws of Software Performance
Natural Laws of Software Performance
 
SharePoint for the .NET Developer
SharePoint for the .NET DeveloperSharePoint for the .NET Developer
SharePoint for the .NET Developer
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Refactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech TalkRefactoring for Software Design Smells - Tech Talk
Refactoring for Software Design Smells - Tech Talk
 
GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...
GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...
GDG Cloud Southlake #16: Priyanka Vergadia: Scalable Data Analytics in Google...
 
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
 
Expanding your impact with programmability in the data center
Expanding your impact with programmability in the data centerExpanding your impact with programmability in the data center
Expanding your impact with programmability in the data center
 
Ztech Connect '19, IBM PureApplication
Ztech Connect '19, IBM PureApplicationZtech Connect '19, IBM PureApplication
Ztech Connect '19, IBM PureApplication
 
Parallel Computing For Managed Developers
Parallel Computing For Managed DevelopersParallel Computing For Managed Developers
Parallel Computing For Managed Developers
 

Kürzlich hochgeladen

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Kürzlich hochgeladen (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Toub parallelism tour_oct2009

  • 2. Parallel Programming with Visual Studio 2010 and the .NET Framework 4 Stephen Toub Microsoft Corporation October 2009
  • 3. Agenda Why Parallelism, Why Now? Difficulties w/ Visual Studio 2008 & .NET 3.5 Solutions w/ Visual Studio 2010 & .NET 4 Parallel LINQ Task Parallel Library New Coordination & Synchronization Primitives New Parallel Debugger Windows New Profiler Concurrency Visualizations
  • 4. Moore’s Law “The number of transistors incorporated in a chip will approximately double every 24 months.” Gordon Moore Intel Co-Founder http://www.intel.com/pressroom/kits/events/moores_law_40th/
  • 5. Moore’s Law: Alive and Well? The number of transistors doubles every two years… More than 1 billiontransistors in 2006! http://upload.wikimedia.org/wikipedia/commons/2/25/Transistor_Count_and_Moore%27s_Law_-_2008_1024.png
  • 6. Moore’s Law: Feel the Heat! Sun’s Surface 10,000 1,000 100 10 1 Rocket Nozzle Nuclear Reactor Power Density (W/cm2) Pentium® processors Hot Plate 8080 ‘70 ‘80 ’90 ’00 ‘10 486 386 Intel Developer Forum, Spring 2004 - Pat Gelsinger
  • 7. Moore’s Law: But Different Frequencies will NOT get much faster! Maybe 5 to 10% every year or so, a few more times… And these modest gains would make the chips A LOThotter! http://www.tomshw.it/cpu.php?guide=20051121
  • 8. The Manycore Shift “[A]fter decades of single core processors, the high volume processor industry has gone from single to dual to quad-core in just the last two years. Moore’s Law scaling should easily let us hit the 80-core mark in mainstream processors within the next ten years and quite possibly even less.”-- Justin Rattner, CTO, Intel (February 2007) “If you haven’t done so already, now is the time to take a hard look at the design of your application, determine what operations are CPU-sensitive now or are likely to become so soon, and identify how those places could benefit from concurrency.”-- Herb Sutter, C++ Architect at Microsoft (March 2005)
  • 9. I'm convinced… now what? Multithreaded programming is “hard” today Doable by only a subgroup of senior specialists Parallel patterns are not prevalent, well known, nor easy to implement So many potential problems Businesses have little desire to “go deep” Best devs should focus on business value, not concurrency Need simple ways to allow all devs to write concurrent code
  • 10. Example: “Race Car Drivers” IEnumerable<RaceCarDriver> drivers = ...; varresults = new List<RaceCarDriver>(); foreach(var driver in drivers) { if (driver.Name == queryName && driver.Wins.Count >= queryWinCount) { results.Add(driver); } } results.Sort((b1, b2) => b1.Age.CompareTo(b2.Age));
  • 11. Manual Parallel Solution IEnumerable<RaceCarDriver> drivers = …; varresults = new List<RaceCarDriver>(); intpartitionsCount = Environment.ProcessorCount; intremainingCount = partitionsCount; varenumerator = drivers.GetEnumerator(); try { using (vardone = new ManualResetEvent(false)) { for(inti = 0; i < partitionsCount; i++) { ThreadPool.QueueUserWorkItem(delegate { while(true) { RaceCarDriver driver; lock (enumerator) { if (!enumerator.MoveNext()) break; driver = enumerator.Current; } if (driver.Name == queryName && driver.Wins.Count >= queryWinCount) { lock(results) results.Add(driver); } } if (Interlocked.Decrement(refremainingCount) == 0) done.Set(); }); } done.WaitOne(); results.Sort((b1, b2) => b1.Age.CompareTo(b2.Age)); } } finally { if (enumerator is IDisposable) ((IDisposable)enumerator).Dispose(); }
  • 12. P LINQ Solution .AsParallel() varresults = from driver in drivers where driver.Name == queryName && driver.Wins.Count >= queryWinCount orderbydriver.Ageascending select driver;
  • 13. Visual Studio 2010Tools, Programming Models, Runtimes Programming Models Tools .NET Framework 4 Visual C++ 10 Visual Studio IDE Parallel LINQ Parallel Pattern Library Parallel Debugger Tool Windows AgentsLibrary Task Parallel Library Data Structures Data Structures Concurrency Runtime Profiler Concurrency Analysis Task Scheduler ThreadPool Task Scheduler Resource Manager Resource Manager Operating System Windows Threads UMS Threads Key: Managed Native Tooling
  • 14. Parallel Extensions What is it? Pure .NET libraries No compiler changes necessary mscorlib.dll, System.dll, System.Core.dll Lightweight, user-mode runtime Key ThreadPool enhancements Supports imperative and declarative, data and task parallelism Declarative data parallelism (PLINQ) Imperative data and task parallelism (Task Parallel Library) New coordination/synchronization constructs Why do we need it? Supports parallelism in any .NET language Delivers reduced concept count and complexity, better time to solution Begins to move parallelism capabilities from concurrency experts to domain experts How do we get it? Built into the core of .NET 4 Debugging and profiling support in Visual Studio 2010
  • 15. Architecture PLINQ Execution Engine .NET Program Parallel Algorithms Declarative Queries Query Analysis Data Partitioning Chunk Range Hash Striped Repartitioning Custom Operator Types Merging Sync and Async Order Preserving Buffered Inverted Map Filter Sort Search Reduce Group Join … C# Compiler VB Compiler Task Parallel Library Coordination Data Structures C++ Compiler Loop replacementsImperative Task Parallelism Scheduling Thread-safe Collections Synchronization Types Coordination Types F# Compiler Other .NET Compiler Threads IL Proc 1 Proc p …
  • 16. Language Integrated Query (LINQ) LINQ enabled data sources Others… C# Visual Basic .NET Standard Query Operators LINQ-enabled ADO.NET LINQ To SQL LINQ To XML LINQ To Objects LINQ To Datasets LINQ To Entities <book> <title/> <author/> <price/> </book> Relational Objects XML
  • 17. Writing a LINQ-to-Objects Query Two ways to write queries Comprehensions Syntax extensions to C# and Visual Basic APIs Used as extension methods on IEnumerable<T> System.Linq.Enumerable class Compiler converts the former into the latter API implementation does the actual work var q = from x in Y where p(x) orderby x.f1select x.f2; var q = Y.Where(x => p(x)).OrderBy(x => x.f1).Select(x => x.f2); var q = Enumerable.Select( Enumerable.OrderBy( Enumerable.Where(Y, x => p(x)), x => x.f1), x => x.f2);
  • 18.
  • 19.
  • 20. Implementation of a Query Operator What might an implementation look like? Does it have to be this way? What if we could do this in… parallel?! public static IEnumerable<TSource> Where<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate) { if (source == null || predicate == null) throw new ArgumentNullException(); foreach (var item in source) { if (predicate(item)) yield return item; } } public static IEnumerable<TSource> Where<TSource>( this IEnumerable<TSource> source, Func<TSource, bool> predicate) { ... }
  • 21. Parallel LINQ (PLINQ) Utilizes parallel hardware for LINQ queries Abstracts away most parallelism details Partitions and merges data intelligently Supports all .NET Standard Query Operators Plus a few knobs Works for any IEnumerable<T> Optimizations for other types (T[], IList<T>) Supports custom partitioning (Partitioner<T>) Built on top of the rest of Parallel Extensions
  • 22. Programming Model Minimal impact to existing LINQ programming model AsParallel extension method ParallelEnumerable class Implements the Standard Query Operators, but for ParallelQuery<T> public static ParallelQuery<T> AsParallel<T>(this IEnumerable<T> source); public static ParallelQuery<TSource> Where<TSource>( this ParallelQuery<TSource> source, Func<TSource, bool> predicate)
  • 23. Writing a PLINQ Query Two ways to write queries Comprehensions Syntax extensions to C# and Visual Basic APIs Used as extension methods on ParallelQuery<T> System.Linq.ParallelEnumerable class Compiler converts the former into the latter As with serial LINQ, API implementation does the actual work var q = from x in Y.AsParallel()where p(x) orderby x.f1select x.f2; var q = Y.AsParallel().Where(x => p(x)).OrderBy(x => x.f1).Select(x => x.f2); var q = ParallelEnumerable.Select( ParallelEnumerable.OrderBy( ParallelEnumerable.Where(Y.AsParallel(), x => p(x)), x => x.f1), x => x.f2);
  • 24. PLINQ Knobs Additional Extension Methods WithDegreeOfParallelism AsOrdered WithCancellation WithMergeOptions WithExecutionMode var results = from driver in drivers.AsParallel().WithDegreeOfParallelism(4) where driver.Name == queryName && driver.Wins.Count >= queryWinCount orderbydriver.Age ascending select driver; var results = from driver in drivers.AsParallel().AsOrdered() where driver.Name == queryName && driver.Wins.Count >= queryWinCount orderbydriver.Age ascending select driver;
  • 25.
  • 26. Operators are replicated across the partitions
  • 27.
  • 28. Partitioning: Load Balancing DynamicScheduling Static Scheduling (Range) CPU0 CPU1 … CPUN CPU0 CPU1 … CPUN 5 5 7 3 1 7 3 1 6 6 8 8 2 2 4 4
  • 29. Several partitioning schemes built-in Chunk Works with any IEnumerable<T> Single enumerator shared; chunks handed out on-demand Range Works only with IList<T> Input divided into contiguous regions, one per partition Stripe Works only with IList<T> Elements handed out round-robin to each partition Hash Works with any IEnumerable<T> Elements assigned to partition based on hash code Custom partitioning available through Partitioner<T> Partitioner.Createavailable for tighter control over built-in partitioning schemes Partitioning: Algorithms
  • 30.
  • 31. Example: (from x in D.AsParallel() where p(x) select x*x*x).Sum();
  • 32. Partition and merge mean synchronization => scalabilitybottleneck
  • 33. Instead, we can fuse operators together:
  • 34. Minimizes number of partitioning/merging steps necessary… Task 1 … … Task 1 … … Task 1 … where p(x) select x3 Sum() D # … Task n… … Task n… … Task n… where p(x) select x3 Sum() … Task 1 … where p(x) select x3 Sum() D # … Task n… where p(x) select x3 Sum()
  • 35. Merging Pipelined: separate consumer thread Default for GetEnumerator() And hence foreach loops AutoBuffered, NoBuffering Access to data as its available But more synchronization overhead Stop-and-go: consumer helps Sorts, ToArray, ToList, etc. FullyBuffered Minimizes context switches But higher latency and more memory Inverted: no merging needed ForAll extension method Most efficient by far But not always applicable Requires side-effects Thread 2 Thread 1 Thread 1 Thread 3 Thread 4 Thread 1 Thread 1 Thread 1 Thread 2 Thread 3 Thread 1 Thread 1 Thread 1 Thread 2 Thread 3
  • 36. Parallelism Blockers Ordering not guaranteed Exceptions Thread affinity Operations with < 1.0 speedup Side effects and mutability are serious issues Most queries do not use side effects, but it’s possible… int[] values = new int[] { 0, 1, 2 };var q = from x in values.AsParallel() select x * 2;int[] scaled = q.ToArray(); // == { 0, 2, 4 }? System.AggregateException object[] data = new object[] { "foo", null, null };var q = from x in data.AsParallel() select o.ToString(); controls.AsParallel().ForAll(c => c.Size = ...); IEnumerable<int> input = …; var doubled = from x in input.AsParallel() select x*2; Random rand = new Random(); var q = from i in Enumerable.Range(0, 10000).AsParallel() select rand.Next();
  • 37. Task Parallel LibraryLoops Loops are a common source of work Can be parallelized when iterations are independent Body doesn’t depend on mutable state / synchronization used Synchronous All iterations finish, regularly or exceptionally Lots of knobs Breaking, task-local state, custom partitioning, cancellation, scheduling, degree of parallelism Visual Studio 2010 profiler support (as with PLINQ) for (inti = 0; i < n; i++) work(i); … foreach (T e in data) work(e); Parallel.For(0, n, i => work(i)); … Parallel.ForEach(data, e => work(e));
  • 38. Task Parallel LibraryStatements Sequence of statements When independent, can be parallelized Synchronous (same as loops) Under the covers May use Parallel.For, may use Tasks StatementA(); StatementB; StatementC(); Parallel.Invoke( () => StatementA() , () => StatementB , () => StatementC() );
  • 39. Task Parallel LibraryTasks System.Threading.Tasks Task Represents an asynchronous operation Supports waiting, cancellation, continuations, … Parent/child relationships 1st-class debugging support in Visual Studio 2010 Task<TResult> : Task Tasks that return results TaskCompletionSource<TResult> Create Task<TResult>s to represent other operations TaskScheduler Represents a scheduler that executes tasks Extensible TaskScheduler.Default => ThreadPool
  • 40.
  • 41.
  • 43.
  • 44. What Can I Do with These Cores? Offload Free up your UI Go faster whenever you can Parallelize the parallelizable Do more Use more data to get better results Add more features Speculate Pre-fetch, Pre-process Evaluate multiple solutions
  • 45. Performance Tips Compute intensive and/or large data sets Work done should be at least 1,000s of cycles Measure, and combine/optimize as necessary Use the Visual Studio concurrency profiler Look for common anti-patterns: load imbalance, lock convoys, etc. Parallelize fine-grained but not too fine-grained e.g. Parallelize outer loop, unless N is insufficiently large to offer enough parallelism Consider parallelizing only inner, or both, at that point Consider unrolling Do not be gratuitous in task creation Lightweight, but still requires object allocation, etc. Prefer isolation & immutability over synchronization Synchronization => !Scalable Try to avoid shared state Have realistic expectations
  • 46. Amdahl’s Law Theoretical maximum speedup determined by amount of sequential code
  • 47. To Infinity And Beyond… The “Manycore Shift” is happening Parallelism in your code is inevitable Visual Studio 2010 and .NET 4 will help Parallel Computing Dev Center http://msdn.com/concurrency Download Beta 2 (“go-live” license) http://go.microsoft.com/?linkid=9692084 Team Blogs Managed: http://blogs.msdn.com/pfxteam Native: http://blogs.msdn.com/nativeconcurrency Tools: http://blogs.msdn.com/visualizeconcurrency Forums http://social.msdn.microsoft.com/Forums/en-US/category/parallelcomputing We love feedback!
  • 48. © 2009 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.