Parallel Extensions to the.NET Framework Daniel Moth Microsoft

Slides:



Advertisements
Similar presentations
Ofir Aspis 1/2010 VS 2010 Targets High Level - IDE New Features VS 2010 As Editor and Platform Demo Editor features Extending.
Advertisements

How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
Hazim Shafi Principal Architect Microsoft Corporation TL19.
Computer Science 320 Clumping in Parallel Java. Sequential vs Parallel Program Initial setup Execute the computation Clean up Initial setup Create a parallel.
INTEL CONFIDENTIAL Threading for Performance with Intel® Threading Building Blocks Session:
An overview of… Luis Guerrero Plain Concepts
OpenMP Optimization National Supercomputing Service Swiss National Supercomputing Center.
James Kolpack, InRAD LLC popcyclical.com. CodeStock is proudly partnered with: Send instant feedback on this session via Twitter: Send a direct message.
FUTURE OF.NET PARALLEL PROGRAMMING Joseph Albahari SESSION CODE: DEV308 (c) 2011 Microsoft. All rights reserved.
CSE 1302 Lecture 21 Exception Handling and Parallel Programming Richard Gesick.
Overview of.NET Framework Sanjay Vyas. Whats New In Base Class Library Declaration & consumption of extensibility points Monitoring for new runtime extension.
DISTRIBUTED AND HIGH-PERFORMANCE COMPUTING CHAPTER 7: SHARED MEMORY PARALLEL PROGRAMMING.
Virtual techdays INDIA │ 9-11 February 2011 Parallelism in.NET 4.0 Parag Paithankar │ Technology Advisor - Web, Microsoft India.
An introduction to F# (part 2) Bogdan Brinzarea-Iamandi Banca Romaneasca 25 February 2010.
Daniel Moth  Parallel Computing Platform Microsoft Corporation TL26.
Department of Computer Science Presenters Dennis Gove Matthew Marzilli The ATOMO ∑ Transactional Programming Language.
Connect with life Bijoy Singhal Developer Evangelist | Microsoft India.
Slides Prepared from the CI-Tutor Courses at NCSA By S. Masoud Sadjadi School of Computing and Information Sciences Florida.
Lecture 4: Parallel Programming Models. Parallel Programming Models Parallel Programming Models: Data parallelism / Task parallelism Explicit parallelism.
Phil Pennington Sr. Developer Evangelist Microsoft Corporation SESSION CODE: WSV325.
Multi-core Programming Thread Profiler. 2 Tuning Threaded Code: Intel® Thread Profiler for Explicit Threads Topics Look at Intel® Thread Profiler features.
 Lynne Hill General Manager Parallel Computing Platform Visual Studio.
Overview of Threading with the.NET Framework  Wallace B. McClure  Scalable Development, Inc. Scalable Development, Inc. Building systems today that perform.
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Parallel Programming in.NET 4.0 Tasks and Threading Ingo Rammer, thinktecture
Parallel Extensions A glimpse into the parallel universe Eric De Carufel
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 4 – Thread Concepts Outline 4.1 Introduction 4.2Definition of Thread 4.3Motivation for.
Chapter 3 Parallel Programming Models. Abstraction Machine Level – Looks at hardware, OS, buffers Architectural models – Looks at interconnection network,
About Me Microsoft MVP Intel Blogger TechEd Israel, TechEd Europe Expert C++ Book
MATRIX MULTIPLY WITH DRYAD B649 Course Project Introduction.
CS 346 – Chapter 4 Threads –How they differ from processes –Definition, purpose Threads of the same process share: code, data, open files –Types –Support.
Lecture 21 Parallel Programming Richard Gesick. Parallel Computing Parallel computing is a form of computation in which many operations are carried out.
1 Threads Chapter 11 from the book: Inter-process Communications in Linux: The Nooks & Crannies by John Shapley Gray Publisher: Prentice Hall Pub Date:
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Huseyin YILDIZ Software Design Engineer Microsoft Corporation SESSION CODE: DEV314.
Module 8 Enhancing User Interface Responsiveness.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
TAP into async programming
Visual Studio 2010 and.NET Framework 4 Training Workshop.
CSE Operating System Principles
3/12/2013Computer Engg, IIT(BHU)1 OpenMP-1. OpenMP is a portable, multiprocessing API for shared memory computers OpenMP is not a “language” Instead,
TOPICS WHAT YOU’LL LEAVE WITH WHO WILL BENEFIT FROM THIS TALK.NET developers: familiar with parallel programming support in Visual Studio 2010 and.NET.
THE FUTURE OF C#: GOOD THINGS COME TO THOSE WHO ‘AWAIT’ Joseph Albahari SESSION CODE: DEV411 (c) 2011 Microsoft. All rights reserved.
Single Instruction Multiple Threads
Chapter 4 – Thread Concepts
Realizing Concurrency using the thread model
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Chapter 4: Multithreaded Programming
Chapter 4: Threads.
Processes and Threads Processes and their scheduling
Thread Fundamentals Header Advanced .NET Threading, Part 1
Chapter 4 – Thread Concepts
Async or Parallel? No they aren’t the same thing!
Lighting Up Windows Server 2008 R2 Using the ConcRT on UMS
Computer Engg, IIT(BHU)
Task Parallel Library: Design Principles and Best Practices
Distributed Systems - Comp 655
Staying Afloat in the .NET Async Ocean
C++ Forever: Interactive Applications in the Age of Manycore
Chapter 4: Threads.
12 Asynchronous Programming
Realizing Concurrency using the thread model
F# for Parallel and Asynchronous Programming
Visual Studio 2010 and .NET Framework 4 Training Workshop
Chapter 4: Threads & Concurrency
Foundations and Definitions
Outline Chapter 3: Processes Chapter 4: Threads So far - Next -
Chapter 4: Threads.
Lecture 20 Parallel Programming CSE /8/2019.
Presentation transcript:

Parallel Extensions to the.NET Framework Daniel Moth Microsoft

Threading 101 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

The Manycore Shift

void MultiplyMatrices(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]; } Example Code to Parallelize Matrix multiplication (sequential)

int N = size; int P = 2 * Environment.ProcessorCount; int Chunk = N / P; // size of a work chunk ManualResetEvent signal = new ManualResetEvent(false); int counter = P; // use a counter to reduce kernel transitions for (int c = 0; c < P; c++) { // for each chunk ThreadPool.QueueUserWorkItem(o => { int lc = (int)o; for (int i = lc * Chunk; // process one chunk i < (lc + 1 == P ? N : (lc + 1) * Chunk); // respect upper bound i++) { // original loop body 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 (Interlocked.Decrement(ref counter) == 0) { // efficient interlocked ops signal.Set(); // and kernel transition only when done } }, c); } signal.WaitOne(); Error Prone High Overhead Tricks Static Work Distribution Knowledge of Synchronization Primitives Heavy Synchronization Lack of Thread Reuse

Parallel Extensions to the.NET Framework.NET library Supports parallelism in any.NET language, without changes to compilers or the CLR Begins to move concurrency from experts to mainstream.NET developers

void MultiplyMatrices(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]; } Matrix multiplication (Seq)

void MultiplyMatrices(int size, double[,] m1, double[,] m2, double[,] result) { Parallel.For(0, 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]; } } }); } Matrix multiplication (Par)

Sample: Raytracer

AGENDA for Remainder Session Task and friends Imperative Task parallelism Parallel class Imperative Data parallelism Parallel LINQ (PLINQ) Declarative Data parallelism

Task class The lightweight unit of work May run concurrently if it’s “worth it” Supports –parent/child relations –explicit grouping –cancelation –waiting

From Threads to Tasks

TaskManager class Represents a scheduler group –think of it as a fancy thread-pool –one implicit to each AppDomain –can create explicitly for isolation –configurable

“Work Stealing” in Action Worker Thread 1 Worker Thread p Program Thread Task 1 Task 2 Task 3 Task 5 Task 4

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

Parallel.For

Parallel Statements Program statements… …when independent, can be parallelized Synchronous (same as loops) StatementA(); StatementB(); StatementC(); StatementA(); StatementB(); StatementC(); Parallel.Do( () => StatementA(), () => StatementB(), () => StatementC() ); Parallel.Do( () => StatementA(), () => StatementB(), () => StatementC() );

Declarative Data Parallelism Parallel LINQ-to-Objects –Enables LINQ devs to leverage manycore –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; 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;

Parallel LINQ (PLINQ)

PLINQ – Modes of Consumption Pipelined: separate consumer thread –Default for GetEnumerator() And hence foreach loops –More synchronization overhead Stop-and-go: consumer helps –Sorts, ToArray, ToList, GetEnumerator(false), etc. –Minimizes context switches But higher latency and more memory Inverted: no merging needed –ForAll extension method –Most efficient by far But more difficult (side-effects) Thread 2 Thread 4 Thread 1 Thread 3 Thread 1 Thread 3 Thread 1 Thread 2 Thread 1 Thread 3 Thread 2 Thread 1

Summary – Parallel Extensions Task Parallel Library (TPL) –Imperative Task Parallelism – TaskManager etc –Imperative Data Parallelism – Parallel Parallel LINQ (PLINQ) –Declarative Data Parallelism – AsParallel Coordination Data Structures (CDS) –Thread-safe collections, Work exchange constructs, Phased operation primitives, Locks, Initialization support

Resources Binaries, Code, Forums, blogs, videos, screencasts, podcasts, articles, samples My blog for resources to this session

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