Connect with life www.connectwithlife.co.in Bijoy Singhal Developer Evangelist | Microsoft India.

Slides:



Advertisements
Similar presentations
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Advertisements

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Windows 8 (1) (2) (3) Windows 8 (1) (2) (3)
Parallel Performance Tools in Visual Studio 2010.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
James Kolpack, InRAD LLC popcyclical.com. CodeStock is proudly partnered with: Send instant feedback on this session via Twitter: Send a direct message.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Parallel Extensions to the.NET Framework Daniel Moth Microsoft
System.Threading.Tasks Task Represents an asynchronous operation Supports waiting, cancellation, continuations, … Parent/child relationships 1 st -class.
* Archiving provided by Exchange.
Stephen Toub Parallel Computing Platform Microsoft Corporation.
Feature: Purchase Requisitions - Requester © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Vishal Mehrotra Senior Lead Program Manager | Microsoft |
demo Default WANGPSLookup Default WANGPS.
Feature: Payroll and HR Enhancements © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Daniel Moth  Parallel Computing Platform Microsoft Corporation TL26.
Connect with life Bijoy Singhal Developer Evangelist | Microsoft India |
Co- location Mass Market Managed Hosting ISV Hosting.
Connect with life Vinod Kumar M Technology Evangelist | Microsoft
Multitenant Model Request/Response General Model.
Connect with life Praveen Srvatsa Director | AsthraSoft Consulting Microsoft Regional Director, Bangalore Microsoft MVP, ASP.NET.
Ravi Sankar Technology Evangelist | Microsoft Corporation
Steve Teixeira Principal Product Unit Manager Parallel Developer Tools Microsoft Corporation.
Announcing Demo Announcing.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
 Rico Mariani Architect Microsoft Corporation.
Feature: Assign an Item to Multiple Sites © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Connect with life Connect with life
Windows Azure Connect Name Title Microsoft Corporation.
NEXT: Overview – Sharing skills & code.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Document Attachment –Replace OLE Notes © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
Connect with life Janakiram MSV Sr. Technology Strategist | MS India Development Center Siddharth Jagtiani Sr. Program Manager.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Sudesh Krishnamoorthy Developer Technology Specialist | Microsoft |
Rahul Gangwar Partner Technical Consultant | Microsoft |
 Joshua Goodman Group Program Manager Microsoft Corporation.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
Huseyin YILDIZ Software Design Engineer Microsoft Corporation SESSION CODE: DEV314.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Parallel Pattern Library Resource Manager Task Scheduler Task Parallel Library Task Parallel Library Parallel LINQ Managed Native Key: Threads Operating.
Connect with life Vedant Kulshreshtha Technology Solutions Professional – SharePoint | Microsoft India
demo Demo.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
Feature: Suggested Item Enhancements – Analysis and Assignment © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and.
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
Connect with life Cheryl Johnson VSTS Solution Expert | Canarys Automations Pvt Ltd Performance Testing.

Connect with life Bijoy Singhal Microsoft India Jadeja Dushyantsinh A Microsoft India.
Connect with life Tejasvi Kumar Developer Technology Specialist | Microsoft India
S4 Solution Specialist Sales Summit
Возможности Excel 2010, о которых следует знать
Title of Presentation 12/2/2018 3:48 PM
F# for Parallel and Asynchronous Programming
Pedro Miguel Teixeira Senior Software Developer Microsoft Corporation
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
Presentation transcript:

Connect with life Bijoy Singhal Developer Evangelist | Microsoft India

Session Objectives Understand why we need parallelism? How PLINQ integrates parallelism into.NET? How does PLINQ work? What are Coordination Data Structures? Demo: PLINQExamples NOTE: This presentation is based on June 2008 CTP of parallel extensions. Things may change in future.

The Manycore Shift

What's the Problem? 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 devs should focus on business value, not concurrency Need simple ways to allow all devs to write concurrent code

5 Example: “Baby Names” IEnumerable babies =...; var results = new List (); foreach (var baby in babies) { if (baby.Name == queryName && baby.State == queryState && baby.Year >= yearStart && baby.Year <= yearEnd) { results.Add(baby); } results.Sort((b1, b2) => b1.Year.CompareTo(b2.Year));

6 Manual Parallel Solution IEnumerable babies = …; var results = new List (); int partitionsCount = Environment.ProcessorCount * 2; int remainingCount = partitionsCount; var enumerator = babies.GetEnumerator(); try { using (ManualResetEvent done = new ManualResetEvent(false)) { for (int i = 0; i < partitionsCount; i++) { ThreadPool.QueueUserWorkItem(delegate { var partialResults = new List (); while(true) { BabyInfo baby; lock (enumerator) { if (!enumerator.MoveNext()) break; baby = enumerator.Current; } if (baby.Name == queryName && baby.State == queryState && baby.Year >= yearStart && baby.Year <= yearEnd) { partialResults.Add(baby); } lock (results) results.AddRange(partialResults); if (Interlocked.Decrement(ref remainingCount) == 0) done.Set(); }); } done.WaitOne(); results.Sort((b1, b2) => b1.Year.CompareTo(b2.Year)); } finally { if (enumerator is Idisposable) ((Idisposable)enumerator).Dispose(); } Synchronization Knowledge Inefficient locking Manual aggregation Lack of foreach simplicity Tricks Heavy synchronization Lack of thread reuse Non-parallel sort

7 LINQ Solution var results = from baby in babies where baby.Name == queryName && baby.State == queryState && baby.Year >= yearStart && baby.Year <= yearEnd orderby baby.Year ascending select baby;

8 Example: Matrix Multiplication 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]; }

9 Manual Parallel Solution int N = size; int P = 2 * Environment.ProcessorCount; int Chunk = N / P; ManualResetEvent signal = new ManualResetEvent(false); int counter = P; for (int c = 0; c < P; c++) { ThreadPool.QueueUserWorkItem(o => { int lc = (int)o; for (int i = lc * Chunk; i < (lc + 1 == P ? N : (lc + 1) * Chunk); 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) { signal.Set(); } }, c); } signal.WaitOne(); Error Prone Static Work Distribution Potential scalability bottleneck Error Prone

10 Parallel Solution 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]; } }); }

Parallel Extensions Architecture Task Parallel Library Coordination Data Structures.NET Program Proc 1 … … PLINQ Execution Engine C# Compiler VB Compiler C++ Compiler IL Threads + UMS Declarative Queries Declarative Queries Data Partitioning Chunk Range Hash Striped Repartitioning Data Partitioning Chunk Range Hash Striped Repartitioning Operator Types Map Filter Sort Search Reduction Operator Types Map Filter Sort Search Reduction Merging Async (pipeline) Synch Order Preserving ForAll Merging Async (pipeline) Synch Order Preserving ForAll Proc p Parallel Algorithms Query Analysis Thread-safe Collections Synchronization Types Coordination Types Thread-safe Collections Synchronization Types Coordination Types Loop replacements Imperative Task Parallelism Scheduling Loop replacements Imperative Task Parallelism Scheduling PLINQ TPL or CDS F# Compiler Other.NET Compiler

Parallel Extensions to the.NET Framework What is it? Library extensions to the.NET Framework Lightweight, user-mode runtime Supports imperative and declarative, data and task parallelism Common exception handling model Why do we need it? Supports parallelism in any.NET language Delivers reduced concept count and complexity, better time to solution Begins to move parallelism capabilities from concurrency experts to domain experts

Enable LINQ developers to leverage parallel hardware Supports all of the.NET Standard Query Operators Plus a few PLINQ-specific extensions methods Abstracts away parallelism details Partitions and merges data intelligently (“classic” data parallelism) Works for any IEnumerable Parallel LINQ (PLINQ)

Method 1: Comprehension syntax Syntax extensions to C# and Visual Basic Method 2: Method syntax on the APIs: Used as extension methods on IParallelEnumerable System.Linq.ParallelEnumerable class API implementation does the actual work Compiler converts the former into the latter Writing a PLINQ Query var q = ParallelEnumerable.Select( ParallelEnumerable.OrderBy( ParallelEnumerable.Where(Y.AsParallel(), x => p(x)), x => x.f1), x => x.f2); var q = ParallelEnumerable.Select( ParallelEnumerable.OrderBy( ParallelEnumerable.Where(Y.AsParallel(), x => p(x)), x => x.f1), x => x.f2); var q = Y.AsParallel().Where(x => p(x)). OrderBy(x => x.f1).Select(x => x.f2); var q = from x in Y.AsParallel() where p(x) orderby x.f1 select x.f2;

Partitioning Input to a single operator is partitioned into p disjoint subsets Operators are replicated across the partitions Example (from x in D.AsParallel() where p(x) select x*x*x).Sum(); Each partition executes in (almost) complete isolation … Task n … … Task 1 … where p(x) D select x 3 Sum()

Partitioning, cont. Types of partitioning Chunk Works with any IEnumerable Single enumerator shared; chunks handed out on-demand Range Works only with IList Input divided into contiguous regions, one per partition Striped Elements handed out round-robin to each partition Hash Works with any IEnumerable Elements assigned to partition based on hash code Repartitioning sometimes necessary

Pipelined: separate consumer thread Default for GetEnumerator() And hence foreach loops Access to data as its available But more synchronization overhead Stop-and-go: consumer helps Minimizes context switches But higher latency, more memory Sorts, ToArray, ToList, etc. Inverted: no merging needed ForAll extension method Most efficient by far But not always applicable Thread 2 Thread 4 Thread 1 Thread 3 Thread 1 Thread 3 Thread 1 Thread 2 Thread 1 Thread 3 Thread 2 Thread 1 Merging

Coordination Data Structures Thread-safe collections ConcurrentStack ConcurrentQueue ConcurrentLinkedList ConcurrentSet ConcurrentBag … Work exchange BlockingCollection … Phased operation CountdownEvent … Locks ManualResetEventSlim SemaphoreSlim SpinLock SpinWait … Initialization LazyInit WriteOnce …

PLINQExamples

ails.aspx?familyid=348F73FD-593D-4B3C- B C50D2B0F3&displaylang=en

References Parallel Extensions Team Blog Parallel Extensions June 2008 CTP Help file

Feedback / QnA Your Feedback is Important! Please take a few moments to fill out our online feedback form For detailed feedback, use the form at Or us at Use the Question Manager on LiveMeeting to ask your questions now!

Contact Blog Address blogs.msdn.com/bsinghal Address

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