Overview Of Parallel Development - Ericnel

  • 1,083 views
Uploaded on

VBUG Newcastle delivery 24th February 2009 by Eric Nelson

VBUG Newcastle delivery 24th February 2009 by Eric Nelson

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,083
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
41
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • 06/08/09 02:01 © 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.

Transcript

  • 1. Overview of Parallel Development Eric Nelson http://geekswithblogs.net/iupdateable http://blogs.msdn.com/goto100 http://twitter.com/ericnel
  • 2. Agenda
    • Overview of what we are up to
    • Drill down into parallel programming for managed developers
  • 3. Things I learnt...
    • We have a very large investment in parallel computing
      • We have “something for everyone”
      • It is not all synced, it is sometimes overlapping
    • It is a big topic
      • Managed vs native vs client vs server vs task vs data...
    • Even with the investment, design/code/test for parallel is far harder
      • Locking, Deadlocks, Livelocks
    • It is about getting ready for the future
      • Code today – run better tomorrow?
    • VS2010 CTP – not a great place for parallel
      • Single core in guest
      • Unsupported route to use Hyper-V
    • Easiest route to dabble – Microsoft Parallel Extensions June CTP for VS2008
  • 4. Buying a new Processor £100 - £300 2-3GHz 2 cores or 4 64-bit Core Core
  • 5. Buying a new Processor Core Core Core Core £200 - £500 2-3GHz 4 cores with HT 64-bit QuickPath Interconnect Memory Controller
  • 6. Where will it all end? Unisys ES7000 (7600R) used with kind permission of Mr Henk var der Valk, Unisys, NL
  • 7. Was it a wise purchase? Windows OS App 1 App 2 ... App 1 .NET CLR .NET Framework My Code
  • 8. Was it a wise purchase?
    • Some environments scale to take advantage of additional CPU cores (mostly server-side)
    • A lot of code does not (mostly client-side)
      • This code will see little benefit from future hardware advances 
    ASP.NET Web Forms/Services WCF Services WF Engine ... .NET ThreadPool or Custom Threading Strategy
  • 9. What happened to “The Free Lunch”? Bad sequential code will run faster on a faster processor Just using parallel code is not enough Bad parallel code WILL NOT run faster on more cores
  • 10. Applications Can Scale Well Graphics Rendering – Physical Simulation -- Vision – Data Mining -- Analytics
  • 11.
    • Multithreaded programming is “hard” today
      • Doable by only a subgroup of senior specialists
      • Parallel patterns are not prevalent, well known, nor easy to implement
      • So many potential problems
        • Races, deadlocks, livelocks, lock convoys, cache coherency overheads, lost event notifications, broken serializability, priority inversion, and so on…
    • Businesses have little desire to “go deep”
      • Best developers should focus on business value, not concurrency
      • Need simple ways to allow all developers to write concurrent code
    What's The Problem?
  • 12.
    • 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];
    •             }
    •         }
    •     }
    • }
  • 13.
    • void MatrixMult(
    • int size, double ** m1, double ** m2, double ** result) {
    •    int N = size;                          
    •    int P = 2 * 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);
    • }
    Synchronization Knowledge Error prone Heavy synchronization Static partitioning Lack of thread reuse Tricks Lots of boilerplate
  • 14. Microsoft Parallel Computing Technologies Task Concurrency Data Parallelism Distributed/ Cloud Computing Local Computing
    • 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
    CCR Maestro TPL / PPL Cluster TPL Cluster PLINQ MPI / MPI.Net WCF Cluster SOA WF PLINQ TPL / PPL CDS OpenMP WF Compute Shader
  • 15. Visual Studio 2010 Tools / Programming Models / Runtimes Threads Operating System Concurrency Runtime Programming Models Task Scheduler Resource Manager Integrated Tooling Programming Models Concurrency Runtime Parallel Pattern Library Resource Manager Task Scheduler Task Parallel Library PLINQ Managed Library Native Library Agents Library ThreadPool Data Structures Data Structures Tools Parallel Debugger Tool Profiler Concurrency Analysis
  • 16. Explicit Tasking Support
    • .NET 4.0
    • Task Parallel Library
    • Task, TaskFactory
    • Parallel.For
    • Parallel.Foreach
    • Parallel.Invoke
    • Concurrent data structures
    • Visual Studio 2010 C++
    • Parallel Pattern Library
    • task, task_group
    • parallel_for
    • parallel_for_each
    • parallel_invoke
    • Concurrent data structures
    • Primitives for message passing
    • User-mode locks
  • 17. Task Parallel Library ( TPL )
  • 18. Task No Threading to Threading to Tasks
  • 19. User Mode Scheduler Program Thread CLR Thread Pool Global Queue Worker Thread 1 Worker Thread p
  • 20. User Mode Scheduler For Tasks Program Thread Task 1 Task 2 Task 3 Task 5 Task 4 Task 6 CLR Thread Pool: Work-Stealing Worker Thread 1 Worker Thread p Global Queue Local Queue Local Queue
  • 21. Debugger Support
    • Support both managed and native
    • Parallel Tasks
    • Parallel Stacks
  • 22. Higher Level Constructs
    • Even with Task there are common patterns that build into higher level abstractions
    • The Parallel class
      • Invoke, For, For<T>, Foreach
    • Care needs to be taken with state, ordering
      • “ This is not your Father’s for loop”
  • 23. Parallel Parallel.ForEach Parallel.Invoke
  • 24. 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;
  • 25. P arallel LINQ
  • 26. What Next?
    • Download VS 2010 CTP
      • Remember to set the clock back
    • Or
    • Download Parallel Extensions June CTP for VS2008
    • Experiment with runtime and API
      • Team is working on Visual Studio 2010 beta
      • Very open to feedback
      • Join in the discussion forums
      • http://blogs.msdn.com/pfxteam/
  • 27. Parallel Computing Resources
    • Downloads, Binaries, Code, Forums, Blogs, Videos, Screencasts, Podcasts, Articles, Samples
      • http://msdn.com/concurrency
      • http://blogs.msdn.com/pfxteam/