Presentation is loading. Please wait.

Presentation is loading. Please wait.

Vance Morrison Performance Architect Microsoft Corporation.

Similar presentations


Presentation on theme: "Vance Morrison Performance Architect Microsoft Corporation."— Presentation transcript:

1

2 Vance Morrison Performance Architect Microsoft Corporation

3 3

4 For all the same Reasons it is for People

5

6

7 7 int loopCount = 10; for (int tId = 1; tId <= 3; tId++) {// Create three work items. ThreadPool.QueueUserWorkItem(delegate { for (int i = 0; i < loopCount; i++) { Console.WriteLine("Thread i={0} time: {1}", i, DateTime.Now); Thread.Sleep(1000); } }); } Console.WriteLine("Waiting for workers. Hit return to end program."); Console.ReadLine(); You can capture variables Anonymous Delegate

8

9 9 Work items with 10% CPU on a dual core system using ThreadPool.QueueUserWorkItem(). Reasons for perf degradation 1.Context switches 2.Memory contention 3.Hot Locks 4.Disk Contention 5.Network Contention

10

11 Task task1 = Task.Create(delegate { Console.WriteLine("In task 1"); Thread.Sleep(1000); // do work Console.WriteLine("Done task 1"); }); Task task2 = Task.Create(delegate { Console.WriteLine("In task 2"); Thread.Sleep(2000); // do work Console.WriteLine("Done task 2"); }); If (userAbort) { task1.Cancel(); task2.Cancel(); } Task.WaitAll(task1, task2); Tasks now have handles Exceptions in tasks propagated on wait You can cancel work You can wait on the handle to synchronize

12 Future left = Future.Create(delegate { Thread.Sleep(2000); // do work return 1; }); Future right = Future.Create(delegate { Thread.Sleep(1000); // do work return 1; }); Console.WriteLine("Answer {0}", left.Value + right.Value); Left and right represent integers, but they may not be computed yet Asking for the value forces the wait if the future is not already done In this case the right value was done, so no wait was needed

13 for(int i = 0; i < n; i++) { work(i); } foreach(T e in data) { work(e); } Parallel.For(0, n, i => { work(i); } Parallel.ForEach(data, e => { work(e); }

14

15

16

17 Related Sessions Session TitleSpeakerDayTimeLocation Microsoft Visual Studio: Bringing out the Best in Multicore SystemsHazim ShafiMon 1:45-3:00PM 502A TL24 Improving.NET Application Performance and ScalabilitySteve CarolWed 1:15-2:30PM 153 Parallel Programming for Managed Developers with the Next Version of Microsoft Visual Studio Daniel MothWed 10:30-11:45AM Petree Hall Parallel Symposium: Addressing the Hard Problems with ConcurrencyDavid CallahanThurs 8:30-10:00AM 515A Parallel Symposium: Future of Parallel ComputingDave DetlefsThurs 12:00-1:30PM 515A

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


Download ppt "Vance Morrison Performance Architect Microsoft Corporation."

Similar presentations


Ads by Google