30
Parallel Programming for Managed Developers with Visual Studio 2010 Daniel Moth Parallel Computing Platform Microsoft Corporation http://www.danielmoth.com /Blog TL26

Daniel Moth Parallel Computing Platform Microsoft Corporation TL26

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Parallel Programming for Managed Developers with Visual Studio 2010

Daniel Moth Parallel Computing Platform

Microsoft Corporationhttp://www.danielmoth.com/Blog

TL26

Page 2: Daniel Moth  Parallel Computing Platform Microsoft Corporation  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

Page 3: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

What a difference many cores make on the client

demo

Page 4: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

AGENDA

1. Set the scene2. Fine-Grained Parallelism

3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism

Page 5: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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

Page 6: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

From Thread-based toTask-based programming model

demo

Page 7: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Program Thread

CLR Thread Pool

User Mode Scheduler

GlobalQueue

Worker Thread 1

Worker Thread p

Page 8: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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

Page 9: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Task: Rich API

demo

Page 10: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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

Page 11: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

AGENDA CHECKPOINT

1. Set the scene2. Fine-Grained Parallelism

3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism

Page 12: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

New Debugger toolwindows

demo

Page 13: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Debugger Support

Support both managed and native1. Parallel Tasks

2. Parallel Stacks Also supports traditional threading

Page 14: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

AGENDA CHECKPOINT

1. Set the scene2. Fine-Grained Parallelism

3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism

Page 15: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Structured Parallelism

Parallel class static (overloaded) methods helper methods to create/work with Tasks encapsulates common patterns

Page 16: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Parallel.Invoke/ForEach

demo

Page 17: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

AGENDA CHECKPOINT

1. Set the scene2. Fine-Grained Parallelism

3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism

Page 18: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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()

Page 19: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Parallel LINQ

demo

Page 20: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

AGENDA CHECKPOINT

1. Set the scene2. Fine-Grained Parallelism

3. Debugger Support4. Structured Parallelism5. Declarative Data Parallelism

Page 21: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Coordination Data Structures

Thread-safe collectionsConcurrentStack<T>ConcurrentQueue<T>ConcurrentDictionary<TKey,TValue>

Work exchangeBlockingCollection<T>IProducerConsumerCollection<T>

InitializationLazyInit<T>

Phased OperationCountdownEvent Barrier

LocksManualResetEventSlimSemaphoreSlimSpinLockSpinWait

Page 22: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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

Page 23: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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)

Page 24: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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

Page 25: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Page 26: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

Please use the microphones provided

Q&A

Page 27: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

© 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.

Page 28: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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

Page 29: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26

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

Page 30: Daniel Moth  Parallel Computing Platform Microsoft Corporation  TL26