Post on 20-Jan-2016
Parallel Programming for Managed Developers with Visual Studio 2010
Daniel Moth Parallel Computing Platform
Microsoft Corporationhttp://www.danielmoth.com/Blog
TL26
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
AgentsLibrary
ThreadPool
Task Scheduler
Resource Manager
Data Structures
Dat
a St
ruct
ures
Integrated Tooling
Tools
ParallelDebugger
Toolwindows
Profiler Concurrency
Analysis
Programming Models
Concurrency Runtime
What a difference many cores make on the client
demo
AGENDA
1. Set the scene2. Fine-Grained Parallelism
3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism
Threading/Concurrency -> ParallelismOn Single Core Machine
Don’t block the UI Thread Affinity
Async Operations Synchronization Issues
On Multi-core Machine As above... ... plus Improve Actual Performance ... plus create new user experiences
From Thread-based toTask-based programming model
demo
Program Thread
CLR Thread Pool
User Mode Scheduler
GlobalQueue
Worker Thread 1
Worker Thread p
…
CLR Thread Pool: Work-Stealing
Worker Thread 1
Worker Thread p
…
Program Thread
User Mode Scheduler For Tasks
GlobalQueue
LocalQueue
LocalQueue
…
Task 1Task 2Task 3
Task 5Task 4Task 6
Task: Rich API
demo
Task-based Programming Summary
ThreadPoolThreadPool.QueueUserWorkItem(…);
System.Threading.Tasks
Task.StartNew(…);
Startingvar p = Task.StartNew(() => { var t = Task.StartNew(…);});
Parent/Child
var f = Future.StartNew(() => C());…int result = f.Value;
Tasks with resultsTask t = Task.StartNew(…);
Task p = t.ContinueWith(…);t.Wait(2000);t.Cancel();
Continue/Wait/Cancel
AGENDA CHECKPOINT
1. Set the scene2. Fine-Grained Parallelism
3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism
New Debugger toolwindows
demo
Debugger Support
Support both managed and native1. Parallel Tasks
2. Parallel Stacks Also supports traditional threading
AGENDA CHECKPOINT
1. Set the scene2. Fine-Grained Parallelism
3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism
Structured Parallelism
Parallel class static (overloaded) methods helper methods to create/work with Tasks encapsulates common patterns
Parallel.Invoke/ForEach
demo
AGENDA CHECKPOINT
1. Set the scene2. Fine-Grained Parallelism
3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism
Declarative Data Parallelism
Parallel LINQ-to-Objects (PLINQ) Enables LINQ devs to leverage multiple cores Fully supports all .NET standard query operators Minimal impact to existing LINQ model
var q = from p in people where p.Name == queryInfo.Name && p.State == queryInfo.State && p.Year >= yearStart && p.Year <= yearEnd orderby p.Year ascending select p;
.AsParallel()
Parallel LINQ
demo
AGENDA CHECKPOINT
1. Set the scene2. Fine-Grained Parallelism
3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism
Coordination Data Structures
Thread-safe collectionsConcurrentStack<T>ConcurrentQueue<T>ConcurrentDictionary<TKey,TValue>
Work exchangeBlockingCollection<T>IProducerConsumerCollection<T>
InitializationLazyInit<T>
Phased OperationCountdownEvent Barrier
LocksManualResetEventSlimSemaphoreSlimSpinLockSpinWait
Summary
Task Parallel Library Task + User Mode Work Stealing Scheduler Parallel.Invoke/For/ForEach
Parallel LINQ Coordination Data Structures Debugger toolwindows
Parallel Tasks Parallel Stacks
Parallel Performance Analyzer (see TL19)
Visual Studio 2010 & Framework 4.0
Embrace Parallelism and
Create New Experiences
Parallel Computing @ PDC2008
Monday (watch them on video) Microsoft Visual Studio: Bringing out the Best in
Multicore Systems Parallel Programming for C++ Developers in the
Next Version of Microsoft Visual StudioLater Today (1:15 PM – 2:30 PM)
Concurrency Runtime Deep Dive: How to Harvest Multicore Computing Resources
Thursday Symposium (8:30 AM – 1:30 PM) Addressing the Hard Problems of Concurrency Parallel Computing Application Architectures and
Opportunities Future of Parallel Computing (Panel)
Parallel Computing Resources
Downloads, Binaries, Code, Forums, Blogs, Videos, Screencasts,
Podcasts, Articles, Samples
Visual Studio 2010 CTP on your PDC drive
http://msdn.com/concurrency
Evals & Recordings
Please fill
out your
evaluation for
this session at:
This session will be available as a recording at:
www.microsoftpdc.com
Please use the microphones provided
Q&A
© 2008 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.
MSFT Parallel Computing Technologies
Task Concurrency
Data Parallelism
Distributed/Cloud Computing
LocalComputing
•Robotics-based manufacturing assembly line•Silverlight Olympics viewer
•Enterprise search, OLTP, collab•Animation / CGI rendering•Weather forecasting•Seismic monitoring•Oil exploration
•Automotive control system •Internet –based photo services
•Ultrasound imaging equipment •Media encode/decode•Image processing/ enhancement•Data visualization
IFx / CCR
Maestro
TPL / PPL
D-TPL
D-PLINQ
MPI / MPI.Net
WCF
Cluster SOA
WF
PLINQ
TPL / PPL
CDS
OpenMP
Comprehensive View Of Concurrency
Area Descriptions Example Scenarios
Imperative Data Parallelism
Apply the same operation to common collections/sets in parallel. Looping, data partitioning, reductions, scans, etc.
Medical imagingBond pricing
Task Parallelism Simultaneously perform multiple independent operations. Divide-and-conquer, tasks, threads, fork/join, futures, etc.
Process control automation
Shared Resources Building blocks for implementing concurrent components. Scalable and thread-safe collections, locks, etc.
Middle-tier configuration/state management
Declarative Data Parallelism
Define what computation needs to be done, without the how. Selections, filters, joins, aggregations, groupings, etc.
Statistical modeling
Coordination Exploit latent operations by doing work while waiting for data. Asynch I/O, async interaction points, message passing, etc.
Streaming audio
Task Parallel LibraryParallel Pattern LibraryOpenMP, Cluster SOA
Coordination Data StructuresTransactional Memory
MPI, MPI.net, CCRNative Agents and Messaging
Maestro
PLINQ