Parallel Programming Session 1
Parallel Programming Session 1
Why
What
Managed APIs/runtime (.NET 4)
Tools (in the VS2010 IDE)
Why
The Manycore Shift
Why
Problem and Goals
Goals
Developer productivity
Performance
Agenda Checkpoint
Why
What
Managed APIs/runtime (.NET 4)
a.k.a. Parallel Extensions to .NET
Tools (in the VS2010 IDE)
Parallel Extensions to .NET
Overview
Parallel.For(0, N, i =>
{
Compute(i);
});
Parallel.ForEach(data, e => Compute(e));
Task Parallel Library (TPL)
Loops
DEMO: Raytracer
Task Parallel Library (TPL)
Regions
A();
B();
C();
Parallel.Invoke(pops,
() => A(),
() => B(),
() => C());
Task Parallel Library (TPL)
Tasks
DEMO: Reversi
Parallel LINQ (PLINQ)
Language Integrated Query (LINQ) Overview
Visual Basic C# Others…
.AsParallel().WithDegreeOfParallelism(4)
.WithCancellation(myToken)
.WithMergeOptions(ParallelMergeOptions.NotBuffered)
.WithExecutionMode(ParallelExecutionMode.ForceParallelism)
Parallel LINQ (PLINQ)
Supported Operators
In .NET 4, ~50 operators w/ ~175 overloads
Aggregate(3) GroupBy(8) SequenceEqual(2)
All(1) GroupJoin(2) Single(2)
Any(2) Intersect(2) SingleOrDefault(2)
AsEnumerable(1) Join(2) Skip(1)
Average(20) Last(2) SkipWhile(2)
Cast(1) LastOrDefault(2) Sum(20)
Concat(1) LongCount(2) Take(1)
Contains(2) Max(22) TakeWhile(2)
Count(2) Min(22) ThenBy(2)
DefaultIfEmpty(2) OfType(1) ThenByDescending(2)
Distinct(2) OrderBy(2) ToArray(1)
ElementAt(1) OrderByDescending(2) ToDictionary(4)
ElementAtOrDefault(1) Range(1) ToList(1)
Empty(1) Repeat(1) ToLookup(4)
Except(2) Reverse(1) Union(2)
First(2) Select(2) Where(2)
FirstOrDefault(2) SelectMany(4) Zip(1)
Parallel LINQ (PLINQ)
Partitioning Cancellation
{Orderable}Partitioner<T>
Partitioner.Create(…) CancellationTokenSource
CancellationToken
ThreadPool in .NET 3.5
Global
Queue
Worker Worker
Work Item 3 …
Thread 0 Thread N
Other
WorkThreads
Item 21
ThreadPool in .NET 4
Local Local
Work- Work-
Lock-free Stealing Stealing
Global Queue Queue
Queue
Worker …
Worker
Work Item 453
Thread 0 Thread N
Other
WorkThreads
Item 1
2
Agenda Checkpoint
Why
What
Managed APIs/runtime (.NET 4)
a.k.a. Parallel Extensions to .NET
Tools (in the VS2010 IDE)
Debugging: Parallel Tasks and Parallel Stacks
Concurrency Visualizer
Tools
Parallel Debugging
“Parallel Tasks”
“Parallel Stacks”
Tools
“Parallel Tasks”
Zoom
Bird’s eye view
control
Other
Processes
Number
Idle
of cores
Time
Your
Process
Tools
Concurrency Visualizer: Threads View
Measure time
Hide
for interesting
Uninteresting
segments
threads
Active
Legend
Call Usage
Stacks Hints
Tools
Concurrency Visualizer: Cores View
Color per
thread
Migration
visualization
Related Content