Parallel Programming in.NET 4.0 Tasks and Threading Ingo Rammer, thinktecture

Slides:



Advertisements
Similar presentations
Computer Science 320 Clumping in Parallel Java. Sequential vs Parallel Program Initial setup Execute the computation Clean up Initial setup Create a parallel.
Advertisements

James Kolpack, InRAD LLC popcyclical.com. CodeStock is proudly partnered with: Send instant feedback on this session via Twitter: Send a direct message.
Parallel Extensions to the.NET Framework Daniel Moth Microsoft
Tips, Tricks, and Techniques for Building Killer Silverlight Apps Jeff Prosise
Build-Deploy-Test with Visual Studio Lab Management 2010 Pieter Gheysens Visual Studio ALM MVP – Sparkles User Group Lead VISUG (
HTML5 That’s what you need to know today Ingo Rammer, thinktecture
Virtual techdays INDIA │ 9-11 February 2011 Parallelism in.NET 4.0 Parag Paithankar │ Technology Advisor - Web, Microsoft India.
Parallel Programming in Visual Studio 2010 Sasha Goldshtein Senior Consultant, Sela Group
& Silverlight, Windows Phone 7, Windows Azure, jQuery, OData and RIA Services. Shaken, not stirred. Kevin
Ingo Rammer thinktecture.
Switching on the cloud for Silverlight MSDN Live Meeting Gill Cleeren Microsoft Regional Director – Silverlight MVP Ordina Belgium.
René Balzano Technology Solution Professional Data Platform Microsoft Switzerland Database Development with SQL Server Data Tools (SSDT)
Best Practices in Virtualizing RDS and VDI: THE Virtual Reality Check Ruben
PARALLEL PROGRAMMING ABSTRACTIONS 6/16/2010 Parallel Programming Abstractions 1.
Parallel Programming in.NET Kevin Luty.  History of Parallelism  Benefits of Parallel Programming and Designs  What to Consider  Defining Types of.
Parallel Programming in.NET 4.0 Tasks and Threading Ingo Rammer, thinktecture
Phil Pennington Sr. Developer Evangelist Microsoft Corporation SESSION CODE: WSV325.
Sofia, Bulgaria | 9-10 October Asynchronous Programming for ASP.NET 2.0 Developers Julie Lerman The Data Farm Julie Lerman The Data Farm.
Chapter 4: Threads. 4.2CSCI 380 Operating Systems Chapter 4: Threads Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux.
Total Workstation Lockdown: Your Action Plan Jeremy Moskowitz, Group Policy MVP Chief Propeller-Head: GPanswers.com Founder: PolicyPak Software (policypak.com)
Overview of Threading with the.NET Framework  Wallace B. McClure  Scalable Development, Inc. Scalable Development, Inc. Building systems today that perform.
NuGet in Depth Making Open Source Suck Less at Microsoft Scott Hanselman
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Parallel Extensions A glimpse into the parallel universe Eric De Carufel
Consuming REST Services from C# SoftUni Team Technical Trainers Software University
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
LINQ, Take Two Realizing the LINQ to Everything Dream Bart J.F. De Smet blogs.bartdesmet.net/bart
Cost architecting for Windows Azure Maarten Balliauw
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Lecture 20: Parallelism & Concurrency CS 62 Spring 2013 Kim Bruce & Kevin Coogan CS 62 Spring 2013 Kim Bruce & Kevin Coogan Some slides based on those.
Huseyin YILDIZ Software Design Engineer Microsoft Corporation SESSION CODE: DEV314.
ALM and practical guidance for VSTS Database Projects Jens K. Suessmeyer Developer hearted, relational minded Visual Studio ALM Core Ranger
Ade Miller Senior Development Manager Microsoft patterns & practices.
Asynchronous Programming Writing Asynchronous Code in C# SoftUni Team Technical Trainers Software University
Migration and Deployment of Office 2010 Steffen Krause Senior Technical Evangelist Microsoft Deutschland GmbH
Windows Azure for IT Pros Kurt CLAEYS (TSP Windows Azure, Microsoft EMEA)
Module 8 Enhancing User Interface Responsiveness.
Plinq Presentation Steen L. Knudsen
Advanced Debugging with Visual Studio Ingo Rammer | thinktecture | Please note: this session is a „classic“
1 OS Review Processes and Threads Chi Zhang
Forthcoming SQL Azure Services: SQL Azure Data Sync & SQL Azure Reporting Mark Scurrell Lead Program Manager Microsoft.
Switch on the LightSwitch Gill Cleeren Microsoft Regional Director / Silverlight MVP Ordina Belgium
Visual Studio 2010 and.NET Framework 4 Training Workshop.
Developing SaaS Applications with the Windows Azure Platform Vittorio Bertocci
Service Manager 2010 Real Life Example: The coffee workflow Mike Resseler & Alexandre Verkinderen Infront Consulting Group.
Building Robust, Maintainable Coded UI Tests with Visual Studio 2010 Brian Keller Sr. Technical Evangelist – Visual Studio ALM
Troubleshooting Group Policy Jeremy Moskowitz, Group Policy MVP Chief Propeller-Head: GPanswers.com Founder: PolicyPak Software (policypak.com) Twitter:
CIS NET Applications1 Chapter 8 – Multithreading and Concurrency Management.
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.
To OData or Not to OData Chris Eargle kodefuguru.com.
What’s new in Azure SDK 1.3 (and 1.4) Peter Himschoot Microsoft Regional Director Belux U2U Trainer/Architect
Asynchronous Programming Writing Concurrent Code in C# SoftUni Team Technical Trainers Software University
Dive into Application Lifecycle Management with Visual Studio 2010
Automating AD Administration with Windows PowerShell
Task Parallel Library: Design Principles and Best Practices
Rock Hard: C++ Evolving
Staying Afloat in the .NET Async Ocean
Glenn Block MEF in the real world Glenn Block
SharePoint & jQuery: Better Together
A walkthrough Corey Hynes | HynesITe, Inc
Build /2/2019 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Unlocking the secrets of REST with WCF
WCF Web API, HTTP your way
Chris Eargle kodefuguru.com
Patterns for Programming Shared Memory
Patterns for Programming Shared Memory
Opalis System Center Integration Packs Deep Dive
Lecture 20 Parallel Programming CSE /8/2019.
9/14/2019 6:51 AM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Presentation transcript:

Parallel Programming in.NET 4.0 Tasks and Threading Ingo Rammer, thinktecture

Ingo Rammer and thinktecture Support and consulting for software architects and developers Architectural Consulting and Prototyping Developer-Coaching and -Mentoring Application Optimization, Troubleshooting, Debugging Architecture and Code Reviews Slides/Samples:

The Problem

128 cores (Yes, this is a real screenshot) 128 cores (Yes, this is a real screenshot)

The future brings more lower speed

Multithreading vs. Parallelism

What do we need? Parallelism, not just multithreading Partitioning of work Queue management Synchronization Today Threads ThreadPool (==> limited API)

.NET <= 3.5 Manual management of parallelism Important Threads: unit of scheduling, not unit of work! ThreadPool: limited API

.NET 4.0 Fine-Grained Parallelism: Task-API and coordination structures (the foundation of it all) Structured Parallelism: Parallel Declarative Parallelism: PLINQ And some underlying optimizations in the ThreadPool

Task API Task t1 = Task.Factory.StartNew(DoSomething); Task t2 = Task.Factory.StartNew(delegate {DoSomething();}); Task t3 = Task.Factory.StartNew(()=>DoSomething()); Something tmp = GetData(); // just dummy parameter Task t4 = Task.Factory.StartNew(p=>((Something)p).DoIt(), tmp); Task t5 = Task.Factory.StartNew(()=>tmp.DoIt()); t1.Wait(); Task.WaitAll(t2,t3,t4); Task.WaitAny(t3,t4,t6); Task t1 = Task.Factory.StartNew(DoSomething); Task t2 = Task.Factory.StartNew(delegate {DoSomething();}); Task t3 = Task.Factory.StartNew(()=>DoSomething()); Something tmp = GetData(); // just dummy parameter Task t4 = Task.Factory.StartNew(p=>((Something)p).DoIt(), tmp); Task t5 = Task.Factory.StartNew(()=>tmp.DoIt()); t1.Wait(); Task.WaitAll(t2,t3,t4); Task.WaitAny(t3,t4,t6);

Tasks with Results Task t1 = Task.Factory.StartNew (() => data.Process()); int val = t1.Result; // blocks until t1 is finished Task t1 = Task.Factory.StartNew (() => data.Process()); int val = t1.Result; // blocks until t1 is finished

Task Continuation var firstTask = new Task (() => First()); var secondTask = firstTask.ContinueWith((t) => Second()); firstTask.Start(); secondTask.Wait(); var firstTask = new Task (() => First()); var secondTask = firstTask.ContinueWith((t) => Second()); firstTask.Start(); secondTask.Wait();

Debugging: Parallel Tasks

Debugging: Parallel Stacks

Structured Parallelism Parallel.Invoke Parallel.Invoke( () => Foo(), () => Bar(), () => Baz()); Parallel.Invoke( () => Foo(), () => Bar(), () => Baz());

Structured Parallelism Parallel.ForEach string[] foo = {"bar","baz","qux"}; Parallel.ForEach(foo, (p) => { DoIt(p); }); // OR...to support stopping: Parallel.ForEach(foo, (p,s) => { DoIt(p); if (p == "baz") s.Stop(); }); // s is implicitly of type ParallelLoopState string[] foo = {"bar","baz","qux"}; Parallel.ForEach(foo, (p) => { DoIt(p); }); // OR...to support stopping: Parallel.ForEach(foo, (p,s) => { DoIt(p); if (p == "baz") s.Stop(); }); // s is implicitly of type ParallelLoopState

int sum2 = lst.Where(p=>p.Index>3123 && p.Index<5892).Sum(p => p.Process()); int sum2 = lst.Where(p=>p.Index>3123 && p.Index<5892).Sum(p => p.Process()); List lst =...; var lst = from p in lst.AsParallel() where p.Index > 3123 && p.Index < 5892 select p; List lst =...; var lst = from p in lst.AsParallel() where p.Index > 3123 && p.Index < 5892 select p; Declarative Parallelism: PLINQ

PLINQ Options lst.AsParallel().WithDegreeOfParallelism(10).AsOrdered().WithMergeOptions(ParallelMergeOptions.FullyBuffered) lst.AsParallel().WithDegreeOfParallelism(10).AsOrdered().WithMergeOptions(ParallelMergeOptions.FullyBuffered)

Cancellation Support Unified cancellation with CancellationSource and CancellationToken Tasks can be manually cancelled, or automatically when parent is cancelled PLINQ-Queries can specify a CancellationToken CancellationSource src = new CancellationSource(); lst.AsParallel().WithCancellation(src.Token).Sum(...); src.Cancel(); CancellationSource src = new CancellationSource(); lst.AsParallel().WithCancellation(src.Token).Sum(...); src.Cancel();

BlockingCollection void ThreadProc() { while (!_workitems.IsCompleted) { var itm = _workitems.Take(); Process(itm); } void ThreadProc() { while (!_workitems.IsCompleted) { var itm = _workitems.Take(); Process(itm); } static BlockingCollection _workItems; void EnqueueProc() { _workItems.Add(123); _workItems.CompleteAdding(); } static BlockingCollection _workItems; void EnqueueProc() { _workItems.Add(123); _workItems.CompleteAdding(); }

ThreadPool Optimizations Local queues Work stealing Locality by LIFO

What you get with.NET 4.0 Fine-Grained Parallelism: Task, Task Structured Parallelism: Parallel.Invoke, Parallel.ForEach Declarative Parallelism: PLINQ //.AsParallel()

Next steps… Think of possible ways to add parallel capabilities to your existing applications. Otherwise you'll only ever use 1/128th of That Big Machine. Resources Daniel Moth's weblog: PFX Team blog: Home:

Stay up to date with MSDN Belux Register for our newsletters and stay up to date: Technical updates Event announcements and registration Top downloads Follow our blog Join us on Facebook LinkedIn: Download MSDN/TechNet Desktop Gadget

TechDays 2011 On-Demand Watch this session on-demand via Channel9 Download to your favorite MP3 or video player Get access to slides and recommended resources by the speakers

THANK YOU