Parallel Development in VS10

676 views

Published on

Powered by MVP roadshow presentation, Riga (LV), Vilnius (LT).

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
676
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • .NET has had support for parallel programming since version 1.0, now referred to as classicthreading, but it was hard to use and made you think too much about managing the parallel aspects ofyour program, which detracts from focusing on what needs to be done.
  • Parallel execution doesn’t come for free. There are overhead costs associated with setting up andmanaging parallel programming features. If you have only a small amount of work to perform, theoverhead can outweigh the performance benefit.
  • Don’t just assume that a parallel solution will give you better performanceand move on.
  • However the thread pool isn’t so great at letting you know when work has been completed orcancelling running threads. The thread pool also doesn’t have any information about the context inwhich the work is created.
  • Dataparallelisim – makeanimage,splitintomanysmallpieciesandperformthesameoperationoneachofthem.Taskparalellisim – takeallsetoftasksandperformthemallatonce.
  • Chunksize – toobig/toosmallChunklayout – memorycache (L2)
  • Ordering– Pipilines, FuturesandDynamicTasks (recursion)
  • Race conditions arise in software when separate processes or threads of execution depend on some shared state
  • A deadlock is a situation in which two or more competing actions are waiting for the other to finish, and thus neither ever does
  • Thread starvation can be caused by creating too many threads
  • Optimizing code for different machine environments
  • If your application is multithreaded is it running in parallel?Operating system allocates time with theCPU to each thread and then rapidly switches between them (known as time slicing)
  • So how does the task scheduler work?1. When tasks are created, they are added to a global task queue.2. The thread pool will create a number of “worker” threads. The exact number that are createddepends on a number of factors such as the number of cores on the machine, current workload, type of work load, and so on. The thread pool utilizes a hill-climbing algorithm thatdynamically adjusts the thread pool to use the optimum number of threads. For example, if thethread pool detects that many threads have an I/O bottleneck, it will create additional threadsto complete the work more quickly. The thread pool contains a background thread that checksevery 0.5 seconds to see whether any work has been completed. If no work has been done (andthere is more work to do), a new thread will be created to perform this work.3. Each worker thread picks up tasks from the global queue and moves it onto its local queue forexecution.4. Each worker thread processes the tasks on its queue.5. If a thread finishes all the work in its local queue, it steals work from other queues to ensure thatwork is processed as quickly as possible. Note that tasks will steal work from the end of the othertask’s queues to minimize the chance that the task has started operating with the work already.
  • The .NET Framework 4 ThreadPool also features a work-stealing algorithm to help make sure that no threads are sitting idle while others still have work in their queues.Stealing work from other thread’s local queue tail.
  • Parallel Development in VS10

    1. 1. Powered by MVP<br />Independent Experts. Real World Answers.<br /> 10. februārī, Rīgā<br />
    2. 2. Parallel Computing withVisual Studio 2010<br />Valdis Iljuconoks<br />Microsoft C# MVP, Latvia<br />
    3. 3. Whywecareaboutthis?<br />
    4. 4. Performance<br />
    5. 5. Avoidmultithreading<br />Parallelprogrammingishard<br />It’sforexperts<br />
    6. 6. Parallelism Will Increase Your<br />Application's Complexity<br />
    7. 7. The keyis<br />measurement<br />
    8. 8. Comparison Matrix (Amdahl'slaw)<br />
    9. 9. Sojust usethreads ?!<br />
    10. 10. Crapcode runningin parallel<br />is justParallelizedcrap code<br />
    11. 11. Where do I start?<br />
    12. 12. TasksvsData<br />ControlFlow<br />ControlandDataFlow<br />
    13. 13. DataParallelism<br />Chunksize<br />Chunklayout<br />Datadependencies<br />
    14. 14. TaskParallelism<br />Taskcount<br />Work per task<br />Dependencies<br />
    15. 15. ControlandDataFlow<br />TaskConstraints<br />ExternalConstraints<br />Orderings<br />
    16. 16. Availability - Framework 4<br />
    17. 17. Some Functionality in 3.5<br />Reactive Extensions (Rx)<br />Parallel Extensions CTP<br />
    18. 18. ParallelLibraryContent<br />
    19. 19. Task Parallel Library (TPL) and Concurrency and Coordination Runtime (CCR)<br />Parallel LINQ (PLINQ)<br />New debugging and profiling tools<br />Coordination data structures<br />Parallel Pattern Library(PPL) C++ only<br />
    20. 20. ParallelLibraryArchitecture<br />
    21. 21. Some of the issues<br />
    22. 22. Some of the issues<br />Race conditions<br />
    23. 23. Some of the issues<br />Race conditions<br />Deadlocks<br />
    24. 24. Some of the issues<br />Race conditions<br />Deadlocks<br />Thread starvation<br />
    25. 25. Some of the issues<br />Race conditions<br />Deadlocks<br />Thread starvation<br />Difficult to code and debug<br />
    26. 26. Some of the issues<br />Race conditions<br />Deadlocks<br />Thread starvation<br />Difficult to code and debug<br />Environmental<br />
    27. 27. Important Concepts<br />
    28. 28. Concurrent != Parallel<br />
    29. 29. Singlecore machine?<br />
    30. 30. Parallelization features<br />Canslow down<br />
    31. 31. Getting started?<br />
    32. 32. Task Factory<br />demo<br />
    33. 33. Parallel.For()Parallel.ForEach()Parallel.Invoke()<br />
    34. 34. Cancelling Task<br />demo<br />
    35. 35. Avoid<br />Console.WriteLine()<br />
    36. 36. Debugging Enhancements<br />Parallel Task Window<br />Parallel Stack Window<br />demo<br />
    37. 37. Deadlocks<br />demo<br />
    38. 38. Parallelism Will Increase Your<br />Application's Complexity<br />
    39. 39. Work Stealing<br />
    40. 40. PLINQ<br />demo<br />
    41. 41. SuccessKeys:<br />Frameworksandlibraries<br />Tools (VS2010)<br />Guidance<br />
    42. 42. Maslow’sHammer<br />
    43. 43. Questions ?<br />
    44. 44. Future Considerations<br />
    45. 45. Dormant GPUs<br />
    46. 46. Distribute work across<br />multiple machines?<br />
    47. 47. Async CTP<br />
    48. 48. Valdis Iljuconoks<br />Software Architect<br />Microsoft C# MVP, Latvia<br />valdis.iljuconoks@dotnet.lv<br />http://dotnet.lv/blogs/vi<br />
    49. 49. Powered by MVP<br />Independent Experts. Real World Answers.<br /> 10. februārī, Rīgā<br />

    ×