300 likes | 339 Views
This comprehensive guide explores parallel programming with Visual Studio 2010, covering programming models, runtimes, tooling, debugging support, structured parallelism, declarative data parallelism, and more. Learn to optimize performance, manage concurrency, and harness the power of multi-core machines. From task-based to thread-based programming, this resource provides valuable insights and practical techniques for creating efficient applications. Explore parallel computing platforms, analyze concurrency patterns, and enhance user experiences with this indispensable toolset.
E N D
TL26 Parallel Programming for Managed Developers with Visual Studio 2010 Daniel Moth Parallel Computing Platform Microsoft Corporation http://www.danielmoth.com/Blog
Visual Studio 2010Tools / Programming Models / Runtimes Integrated Tooling Programming Models Programming Models PLINQ Parallel Debugger Toolwindows Task Parallel Library Parallel Pattern Library Agents Library Data Structures Concurrency Runtime Concurrency Runtime Data Structures Task Scheduler Profiler Concurrency Analysis ThreadPool Task Scheduler Resource Manager Resource Manager Operating System Threads Key: Managed Library Native Library Tools
demo What a difference many cores make on the client
AGENDA • Set the scene • Fine-Grained Parallelism 3. Debugger Support • Structured Parallelism • Declarative Data Parallelism
Threading/Concurrency -> Parallelism On 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
demo From Thread-based toTask-based programming model
User Mode Scheduler CLR Thread Pool Global Queue Worker Thread 1 Worker Thread p … Program Thread
User Mode Scheduler For Tasks CLR Thread Pool: Work-Stealing Local Queue Local Queue Global Queue … Worker Thread 1 Worker Thread p … Task 6 Task 3 Task 4 Task 1 Program Thread Task 5 Task 2
demo Task: Rich API
Task-based Programming Summary ThreadPool ThreadPool.QueueUserWorkItem(…); System.Threading.Tasks Continue/Wait/Cancel Taskt = Task.StartNew(…); Taskp = t.ContinueWith(…); t.Wait(2000); t.Cancel(); Starting Task.StartNew(…); Tasks with results Parent/Child var p = Task.StartNew(() => { vart = Task.StartNew(…);}); varf = Future.StartNew(() => C()); … int result = f.Value;
AGENDA CHECKPOINT • Set the scene • Fine-Grained Parallelism 3. Debugger Support • Structured Parallelism • Declarative Data Parallelism
demo New Debugger toolwindows
Debugger Support Support both managed and native • Parallel Tasks • Parallel Stacks Also supports traditional threading
AGENDA CHECKPOINT • Set the scene • Fine-Grained Parallelism 3. Debugger Support • Structured Parallelism • Declarative Data Parallelism
Structured Parallelism Parallel class • static (overloaded) methods • helper methods to create/work with Tasks • encapsulates common patterns
demo Parallel.Invoke/ForEach
AGENDA CHECKPOINT • Set the scene • Fine-Grained Parallelism 3. Debugger Support • Structured Parallelism • 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 orderbyp.Year ascending select p; .AsParallel()
demo Parallel LINQ
AGENDA CHECKPOINT • Set the scene • Fine-Grained Parallelism 3. Debugger Support • Structured Parallelism • Declarative Data Parallelism
Coordination Data Structures Thread-safe collections ConcurrentStack<T> ConcurrentQueue<T> ConcurrentDictionary<TKey,TValue> Work exchange BlockingCollection<T> IProducerConsumerCollection<T> Initialization LazyInit<T> Phased Operation CountdownEvent Barrier Locks ManualResetEventSlim SemaphoreSlim SpinLock SpinWait
Summary Framework 4.0 • 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 & • 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 Studio Later 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
Q&A Please use the microphones provided
© 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 IFx / CCR • Robotics-based manufacturing assembly line • Silverlight Olympics viewer • Automotive control system • Internet –based photo services WCF Maestro TPL / PPL WF Local Computing Distributed/Cloud Computing • Ultrasound imaging equipment • Media encode/decode • Image processing/ enhancement • Data visualization • Enterprise search, OLTP, collab • Animation / CGI rendering • Weather forecasting • Seismic monitoring • Oil exploration Cluster SOA PLINQ D-PLINQ OpenMP TPL / PPL D-TPL MPI / MPI.Net CDS Data Parallelism
Comprehensive View Of Concurrency Task Parallel Library Parallel Pattern Library OpenMP, Cluster SOA Coordination Data Structures Transactional Memory PLINQ MPI, MPI.net, CCR Native Agents and Messaging Maestro