Huseyin YILDIZ Software Design Engineer Microsoft Corporation SESSION CODE: DEV314.

Slides:



Advertisements
Similar presentations
System.Threading.Tasks Task Represents an asynchronous operation Supports waiting, cancellation, continuations, … Parent/child relationships 1 st -class.
Advertisements

Stephen Toub Parallel Computing Platform Microsoft Corporation.
Ron Jacobs Technical Evangelist Microsoft Corporation SESSION CODE: DEV207.
Jason Tolley Technical Director ROK Technology Pty Ltd SESSION CODE: WEM305.
Joe Kuemerle Lead Developer PreEmptive Solutions - SESSION CODE: DEV306.
Mark Harmsworth – Architecture Nate Bruneau – Engineering Scott Kleven – Program Management Microsoft Corporation SESSION CODE: OSP321.
Sometimes it is the stuff you know that hinders true progress.
Phil Pennington Sr. Developer Evangelist Microsoft Corporation SESSION CODE: WSV325.
Juergen Thomas Principal Program Manager Microsoft Corporation SESSION CODE: DAT314.
The Secrets of Effective Technical Talks: How to Explain Tech without Tucking Them In! Presented by Mark Minasi and Mark Russinovich SESSION CODE: SIA334.
Ashwin Sarin Program Manager Microsoft Corporation SESSION CODE: COS204.
Mark Heneen, Steve Daigle, Tracey Jordan, Zach Beers Microsoft Corporation SESSION CODE: COS205.
Maciej Pilecki Consultant, SQL Server MVP Project Botticelli Ltd. SESSION CODE: DAT403.
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Boris Jabes Senior Program Manager Microsoft Corporation SESSION CODE: DEV319 Scale & Productivity in Visual C
Peter Provost Sr. Program Manager Microsoft Corporation SESSION CODE: DEV403.
Kevin Cox – SQL CAT Microsoft Corporation What are the largest SQL projects in the world? SESSION CODE: DAT305 Srik Raghavan –
Brad Younge Principal Statera, Inc. SESSION CODE: COS304.
Janssen Jones Virtual Machine MVP Indiana University SESSION CODE: VIR403.
About Me Microsoft MVP Intel Blogger TechEd Israel, TechEd Europe Expert C++ Book
Bradley Millington Senior Program Manager Microsoft Corporation SESSION CODE: WEB 306.
Suhail Dutta Program Manager Microsoft Corporation SESSION CODE: DEV402.
Matt winkler program manager microsoft corporation SESSION CODE: ASI303.
Chandrika Shankarnarayan Senior Program Manager Microsoft Corporation SESSION CODE: ASI301.
Satya SK Jayanty Director & Principal Architect D BI A Solutions Peter Saddow Senior Program Manager Microsoft Corporation -SQL Server SESSION CODE: DAT312.
Thomas Deml Principal Program Manager Web Platform and Tools Microsoft Corporation SESSION CODE: WEB308.
Paul Litwin Programmer Manager Fred Hutchinson Cancer Research Center SESSION CODE: WEB206.
Jeff King Senior Program Manager, Visual Studio Microsoft Corporation SESSION CODE: WEB305.
Lori Dirks Expression Community Manager Microsoft Corporation SESSION CODE: WEB309.
Paul Schaeflein, MCT Manager of Advanced Technologies LaSalle Consulting Partners, Inc. SESSION CODE: OSP309.
Ade Miller Senior Development Manager Microsoft patterns & practices.
Dan Holme Director of Training & Consulting Intelliem SESSION CODE: OSP214.
Vineet Sarda Senior Consultant Microsoft Corporation SESSION CODE: WCL302.
Chris Mayo Microsoft Corporation SESSION CODE: UNC207.
Parallel Pattern Library Resource Manager Task Scheduler Task Parallel Library Task Parallel Library Parallel LINQ Managed Native Key: Threads Operating.
Bob Beauchemin Developer Skills Partner SQLskills SESSION CODE: DAT402.
Olivier Bloch Technical Evangelist Microsoft Corporation SESSION CODE: WEM308.
Richard Campbell Co-Founder Strangeloop Networks SESSION CODE: WEB315.
Younus Aftab Program Manager Microsoft Corporation SESSION CODE: WSV324.
Srinath Venkatasubramanian Alliance Manager Sonata Software Limited SESSION CODE: BIP203.
By: Paul D. Sheriff or SESSION CODE: DEV320.
Kate Gregory Gregory Consulting SESSION CODE: DEV316.
SESSION CODE: MGT205 Chris Harris Program Manager Microsoft Corporation.
Reza Chitsaz Senior Program Manager Microsoft Corporation SESSION CODE: DEV302 Building a SharePoint Collaboration Application in Visual Studio 2010.
Andrew Connell, MVP Developer, Instructor & Author Critical Path Training, LLC. SESSION CODE: OSP305.
Introducing Visual Studio 2010: What It Is and Why You Should Care
Pat Altimore Sr. Consultant Microsoft Corporation SESSION CODE: WCL321.
David Ollason Lead Program Manager Microsoft Corporation SESSION CODE: UNC322 The New Communicator “14” Platform.
BIO202 | Building Effective Data Visualizations and Maps with Microsoft SQL Server 2008 Reporting Services BIU08-INT | Using.
Ted Pattison Author / Instructor Critical Path Training SESSION CODE: OSP315.
Martin Woodward Program Manager Microsoft Corporation SESSION CODE: DEV308.
Don Jones Senior Partner and Technologist Concentrated Technology, LLC SESSION CODE: DAT203.
Jesus Rodriguez Chief Architect, Tellago, Inc Microsoft Architect Advisor Microsoft MVP Oracle SOA ACE SESSION CODE: DEV406.
SESSION CODE: COS301. So what do we do?
David A. Carley Senior SDE Microsoft Corporation SESSION CODE: DEV318.
John R. Durant Senior Product Manager Microsoft Corporation SESSION CODE: OSP313.
By: Paul D. Sheriff or SESSION CODE: WCL206.
Cube Measure Group Measure Partition Cube Dimension Dimension Attribute Attribute Relationship Hierarchy Level Cube Attribute Cube Hierarchy.
Brian A. Randell Senior Consultant MCW Technologies SESSION CODE: DEV311.
Christophe Fiessinger & Jan Kalis Senior Technical Product Manager Microsoft Corporation SESSION CODE: OSP209.
Ken Getz Senior Consultant MCW Technologies, LLC SESSION CODE: WCL202.
Tobias Ternstrom Senior Program Manager Lead SQL Server Engine SESSION CODE: DAT404.
Luke Hoban Senior Program Manager Microsoft Corporation SESSION CODE: DEV307.
Lucian Wischik SESSION CODE: DEV401. Advanced Use of the New Microsoft Visual Basic 2010 Language Features Lucian Wischik, VB spec lead.
Andrew Connell, MVP Developer, Instructor & Author Critical Path Training, LLC. SESSION CODE: OSP319.
Tim Laverty – Diego Vega – Program Managers Microsoft Corporation SESSION CODE: DEV305.
Stephen Forte Chief Strategy Officer Telerik stephenforte.net SESSION CODE: DEV303 Building Data Driven RESTful Applications.
Tech Ed North America /20/2018 7:07 AM Required Slide
Task Parallel Library: Design Principles and Best Practices
A Lap Around Internet Explorer 9 For Developers
Presentation transcript:

Huseyin YILDIZ Software Design Engineer Microsoft Corporation SESSION CODE: DEV314

Op1 Op2 Op3 Op4 Op5 CPU1 CPU2 CPU3 CPU4

IEnumerable records = GetRecords(); List results = new List (); foreach(Record record in records) { Result res = ProcessRecord(record); // non-trivial computation per record if (Filter(res)) results.Add(res); // check if result matches our criteria, if so add it into results } // can also be expressed as a simple LINQ statement List results = records.Select(rec => ProcessRecord(rec)).Where(res => Filter(res)).ToList();

IEnumerable records = GetRecords(); List results = new List (); int numWorkers = Environment.ProcessorCount; int activeWorkers = numWorkers; IEnumerator enumerator = records.GetEnumerator(); ManualResetEvent completionEvent = new ManualResetEvent(false); for(int i = 0; i < numWorkers; i++) { ThreadPool.QueueUserWorkItem(delegate { // launch P workers while(true) { Record currentRecord; lock (enumerator) { // grab a record under the lock before processing it if (!enumerator.MoveNext()) break; currentRecord = enumerator.Current; } Result res = ProcessRecord(currentRecord); // non-trivial computation per record if (Filter(res)) // check if result matches our criteria { lock(results) results.Add(res); // if so add it into results list under a lock } if (Interlocked.Decrement(ref activeWorkers) == 0) completionEvent.Set(); }); } completionEvent.WaitOne(); // wait until all workers are done

SAME CODE PARALLELIZED USING PLINQ

Visual Studio IDE.NET Framework 4 Parallel Debugger Concurrency Visualizer Thread Pool Task Scheduler Task Parallel Library Parallel LINQ Sync Primitives Concurrent Collections CLR

PARALLEL LOOPS src Thread 1 rec 1 rec 1 Thread P rec P+1 rec P+1 rec 2P+1 rec 2P+1 rec 2P rec 2P rec 3P rec 3P rec P Parallel.For(0, 100, i => DoWork(i)); Parallel.ForEach(src, rec => DoWork(rec)); Thread 1 i=0 Thread P Thread 2 i=C+1 i=C+2 i=C+3 i=1 i=2 i=P*C+1 i=P*C+2

// Breaking from a parallel loop Parallel.For(0, 1000, (i, state) => { if (SearchFunc(i)) state.Stop(); } // Controlling Degree Of Parallelism ParallelOptions po = new ParallelOptions() { MaxDegreeOfParallelism = 4 }; Parallel.ForEach(source, po, element => ProcessRecord(element) } // Using thread local state Dictionary counts = GetGlobalCounts(); Parallel.ForEach(enumSource, () => { //once per worker thread local init return new List (); }, (record, loopState, threadLocal) => { // actual loop body var result = ProcessRecord(record); if (result.InterestingFlag) threadLocal.Add(result); //cache results }, (threadLocal) => { //end of loop, once per worker combine delegate lock (counts) foreach (Result res in threadLocal) counts[res.GUID] += res.Count; });

PARALLEL LINQ

HOW PLINQ WORKS src Thread 1 where f(x) select y(x) Sum() Thread P where f(x) select y(x) Sum()

PARALLEL LINQ (cont’d)

Enqueue Global Queue (FIFO) Thread 1 Dispatch Loop Thread 2 Dispatch Loop Thread N Dispatch Loop Dequeue T2T2 T3T3 T1T1

Enqueue Global Queue (FIFO) Thread 1 Dispatch Loop Thread 1 Local Queue (LIFO) Thread 2 Dispatch Loop Thread 2 Local Queue (LIFO) Thread N Dispatch Loop Thread N Local Queue (LIFO) Dequeue Enqueue Steal T2T2 T3T3 T4 T4 T5T5 T6T6 T7T7 T8T8 T1T1

// Producer consumer pattern BlockingCollection bc = new BlockingCollection (); // Start the producer Task Task t1 = Task.Factory.StartNew(() => { while(!streamReader.EndOfStream) bc.Add(streamReader.ReadLine()); bc.CompleteAdding(); }); // Start the consumer Task Task t2 = Task.Factory.StartNew(() => { try { // Consume from the blocking collection while (true) Console.WriteLine(bc.Take()); } catch (InvalidOperationException) { // IOE thrown from Take() indicated completed collection Console.WriteLine("That's All!"); } });

Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.

Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub.

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31 st You can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year