Download presentation
Presentation is loading. Please wait.
Published byClinton Warner Modified over 9 years ago
1
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra eric.decarufel@orckestra.com eric@decarufel.net http://blog.decarufel.net
2
Agenda Introduction Overview Library Core TPL (Task Parallel Library) Parallel Linq (PLINQ) Parallel Data Structures Questions
3
Introduction Why do we have to bother? Moore’s law is over, no more free lunch Multi cores systems will be more and more available Type of Parallelism Asynchronous operation (better user experience) Data parallelism Task parallelism Options Manual treading Thread, ThreadPool, BackgroundWorkerThread Asynchronous calls Event driven Problems Resource sharing Locking Non-deterministic sequence of execution Hard to debug
4
Overview
5
Task Parallel Library (TPL) Lightweight task framework (Task) Create(Action ) factory method Wait, WaitAll, WaitAny to catch exception ContinueWith to chain Tasks together Lazy function call Future Task scheduler and manager TaskManager
6
Parallel API Parallel Loops Parallel.For Parallel.ForEach Lazy Initialisation LazyInit Locking SpinWait SpinLock CountdownEvent
7
Parallel API Standard for loop for (int i = 0; i < N; i++) { a[i] = Compute(i); } Parallel for loop Parallel.For(0, N, i => { a[i] = Compute(i); });
8
Parallel Linq (PLINQ) Parallel Query AsParallel() Return to sequential execution AsSequential() Preserve order AsOrdered() Order doesn’t matter AsUnordered()
9
Parallel Linq (PLINQ) var query = from c in Customers where c.Name = “Smith” select c; var query = from c in Customers.AsParallel() where c.Name = “Smith” select c;
10
Parallel Data Structures IConcurrentCollection Add(T item) Remove(out T item) ConcurrentStack Push(T item) TryPop(out T item) ConcurrentQueue Enqueue(T item) TryDequeue(out T item) BlockingCollection Add(T item), Remove(out T item) TryAdd(T item), TryRemove(out T item)
11
CLR Thread Pool: Work-Stealing Worker Thread 1 Worker Thread p Program Thread User Mode Scheduler For Tasks Global Queue Global Queue Local Queue Local Queue Local Queue Local Queue Task 1 Task 2 Task 3 Task 5 Task 4 Task 6
12
Ideas Task stealing Integration into language maybe for later Potentially in parallel Exception Handling Garbage collection Shift from threads to tasks (more than needed) Divide and conquer leads to more parallelism opportunities Use of CPU, GPU or Scale out To get another 100x performance The Power Wall The Complexity Wall The Memory Wall
13
What’s next Visual Studio 2010.NET Framework 4.0 New multi cores computer (4, 16, 32, 64, …) Think parallel!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.