George Chu (朱金生)Principal Group ManagerMicrosoft CorporationDEV318
Agenda
Why Parallelism, Why Now?
Hard problems
What Microsoft is doing about it
Concurrency features in Visual Studio 2010Concurrency Runtime
Programming Models
Tools
Lots of demos along the way
Moore’s Law
“The number of transistors incorporated in a chip will approximately double every 24 months.”
Gordon Moore - Intel
CPUs Are Hitting a WallP
ow
er
De
nsi
ty(W
/cm
2)
4004
8080
80858086
286386
486
Pentium®
processors
1
10
100
1,000
10,000
’70 ’80 ’90 ’00 ’10
Hot Plate
Nuclear Reactor
Rocket Nozzle
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 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, Microsoft (March 2005)
Example: Matrix Multiplication
void MatrixMult(int size,, double** m1, double** m2, double** result)
{for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {result[i][j] = 0;for (int k = 0; k < size; k++) {
result[i][j] += m1[i][k] * m2[k][j];}
}}
}
Manual Parallel Solutionvoid MatrixMult(
int size, double** m1, double** m2, double** result) {int N = size;int P = NUMPROCS; int Chunk = N / P;HANDLE hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);long counter = P;for (int c = 0; c < P; c++) {std::thread t ([&,c] {for (int i = c * Chunk;
i < (c + 1 == P ? N : (c + 1) * Chunk); i++) {for (int j = 0; j < size; j++) {
result[i][j] = 0;for (int k = 0; k < size; k++) {result[i][j] += m1[i][k] * m2[k][j];
}}
}if (InterlockedDecrement(counter) == 0)SetEvent(hEvent);
}); }WaitForSingleObject(hEvent,INFINITE);CloseHandle(hEvent);
}
Static Partitioning
Synchronization Knowledge
Error prone
Lots of boilerplate
Tricks
Lack of thread reuse
Heavy synchronization
Developer! Developer! Developer!
Make parallel programming easier for
developers of all skill levels
Express parallelism
and focus on the problem
Improve efficiency and
scalability
Simplify the design and
testing
Visual Studio 2010Tools/Programming Models/Runtimes
Parallel Pattern Library
Resource Manager
Task Scheduler
Task Parallel Library
PLINQ
Managed Library Native LibraryKey:
ThreadsOperating System
Concurrency Runtime
Programming Models
ThreadPool
Task Scheduler
Resource Manager
Data Stru
ctures D
ata
Stru
ctu
res
Tools
Tools
ParallelDebugger
Tool Windows
Profiler Concurrency
Analysis
AgentsLibrary
Win7: UMS Threads
LINQ Ray Tracer (Image Processing)Game of Life (Simulation)
Visual Studio 2010Tools/Programming Models/Runtimes
Parallel Pattern Library
Resource Manager
Task Scheduler
Task Parallel Library
PLINQ
Managed Library Native LibraryKey:
ThreadsOperating System
Concurrency Runtime
Programming Models
ThreadPool
Task Scheduler
Resource Manager
Data Stru
ctures D
ata
Stru
ctu
res
Tools
Tools
ParallelDebugger
Tool Windows
Profiler Concurrency
Analysis
AgentsLibrary
Win7: UMS Threads
Concurrency RuntimeValue Propositions
Increase developer productivity
Increase scalability
Maximize CPU utilization
Reduce overhead
Avoid system oversubscription
Enable composition of parallel libraries
Provide extensibility
Visual Studio 2010
Programming Models
Concurrency Runtime
Operating System
Concurrency RuntimeKey Components
Task Scheduler
Policy-based instances
Work stealing
Cooperative blocking
Resource Manager
Concurrent Suballocator
Win7 support
Visual Studio 2010
Programming Models
Concurrency Runtime
Operating System
Dynamic Load Balancing
CPU0 CPU1 CPU2 CPU3CPU0 CPU1 CPU2 CPU3
User Mode Scheduler For Tasks
Concurrency Runtime Scheduler
Worker Thread 1
Worker Thread p
…
Program Thread
GlobalQueue
LocalQueue
LocalQueue
…
Task 1Task 2
Task 3Task 5
Task 4
Task 6
Windows 7
UMS threads
> 64 proc
Visual Studio 2010Tools/ProgrammingModels/Runtimes
Parallel Pattern Library
Resource Manager
Task Scheduler
Task Parallel Library
PLINQ
Managed Library Native LibraryKey:
ThreadsOperating System
Concurrency Runtime
Programming Models
ThreadPool
Task Scheduler
Resource Manager
Data Stru
ctures D
ata
Stru
ctu
res
Tools
Tools
ParallelDebugger
Tool Windows
Profiler Concurrency
Analysis
AgentsLibrary
Win7: UMS Threads
Programming ModelsValue Propositions
Increase developer productivity
Make parallel programming safer
Improve scalability
Improve reusability
Visual Studio 2010
Concurrency Runtime
Programming Models
Operating System
Programming ModelsKey Concepts
Parallel Extensions to .NET 4.0PLINQ
Task Parallel Library
Parallel Pattern Library
Asynchronous Agents Library
Visual Studio 2010
Concurrency Runtime
Programming Models
Operating System
Programming ModelsKinds of Parallelism
Task ParallelParallel Invoke
Tasks
Data ParallelParallel Loop
PLINQ
Dataflow ParallelFutures
Continuations
Message Blocks & Asynchronous Agents
Visual Studio 2010
Concurrency Runtime
Programming Models
Operating System
Strassens (Scientific)Option Pricing (Financial Modeling)
Visual Studio 2010Tools/Programming Models/Runtimes
Parallel Pattern Library
Resource Manager
Task Scheduler
Task Parallel Library
PLINQ
Managed Library Native LibraryKey:
ThreadsOperating System
Concurrency Runtime
Programming Models
ThreadPool
Task Scheduler
Resource Manager
Data Stru
ctures D
ata
Stru
ctu
res
Tools
Tools
ParallelDebugger
Tool Windows
Profiler Concurrency
Analysis
AgentsLibrary
Win7: UMS Threads
Visual Studio 2010Value Propositions
Increase the correctness andperformance of your parallelapplications
Programming Models
Concurrency Runtime
Visual Studio 2010
Operating System
Visual Studio 2010Key Concepts
Parallel Debugger WindowsParallel Tasks
Parallel Stacks
Parallel Performance AnalyzerCore Utilization
Thread Blocking
Thread Migration
Programming Models
Concurrency Runtime
Visual Studio 2010
Operating System
Debugging Parallel Apps in VS2010
Parallel Performance Analyzer
Your Process
Idle time
Other processes
Core Utilization/ Concurrency
Thread Blocking
Blocked
Executing
Number of cores
Poor load balancing
Profile LINQ Ray Tracer
Summary of Visual Studio 2010 Concurrency Features
Parallel Extensions to .NET 4.0
Concurrency Runtime
Parallel Pattern Library
Asynchronous Agents Library
Parallel Debugger Tool Windows
Profiler
Parting Advice
Use declarative modes of parallelism where possible
Over-decompose
Win7 is great for concurrency!
Use parallel debugger and profiler tools to uncover and understand concurrency problems!
http://microsoft.com/technet
Resources for IT Professionals
http://microsoft.com/msdn
Resources for Developers
www.microsoft.com/learning
Microsoft Certification & Training Resources
Resources
Related Content
DEV323: “A lap around building SharePoint 2010 applications in VS2010” by Rong LuDay 1 (November 2, 2009): 17:00 – 18:00
DEV377: “Building Business Application in Silverlight” by Xiaoying GuoDay 2 (November 3, 2009): 16:45 – 18:00
Track Resources
Parallel Computing Developer Center: http://msdn.microsoft.com/en-us/concurrency/default.aspx
Native Concurrency Blog: http://blogs.msdn.com/nativeconcurrency
Managed Concurrency Blog: http://blogs.msdn.com/pfxteam/
Complete an
evaluation on
CommNet and
enter to win!
© 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.