Parallel Programming with Microsoft .NET
The patterns&practices team has released Parallel Programming with Microsoft .NET, a book containing guidance for writing parallel programs for .NET. In essence the book contains 6 design patterns for parallel programming accompanied by code samples.
Parallel Programming with Microsoft .NET attempts to deal with the difficult job of decomposing a problem in multiple tasks which can be run in parallel, coordinating the parallel tasks and using data sharing between tasks in order to avoid the need for synchronization which dramatically can affect the performance of a parallel program. For that purpose, the book introduces 6 design patterns used with .NET 4 Task Parallel Library (TPL) and PLINQ:
- Parallel Loops - Used when one needs to apply the same operation to multiple similar data inputs.
- Parallel Tasks – Used when one needs to apply different operations, each with its own data input.
- Parallel Aggregation - “Parallel aggregation introduces special steps in the algorithm for merging partial results. This pattern expresses a reduction operation and includes map/reduce as one of its variations.”
- Futures – Used to integrate data flow with control flow. “A future is a stand-in for a computational result that is initially unknown but becomes available at a later time. The process of calculating the result can occur in parallel with other computations.”
- Dynamic Task Parallelism – Also known as recursive decomposition, this pattern helps adding dynamically created tasks during a computation.
- Pipelines – this pattern combines the parallel task concept with the concurrent queues one, allowing a program to concurrently execute tasks on data inputs and respecting the order in which data is processed.
Each design pattern is accompanied by C#, VB.NET and F# code samples, all available on the Parallel Programming with Microsoft .NET project on CodePlex. The project mentions the intent of the patterns&practices team to produce a companion book for C++ developers using the Parallel Patterns Library (PPL) and Asynchronous Agents Library.
The guide contains advice on integrating the parallel design patterns with other OOP patterns such as Façades, Decorators, and Repositories. It also shows how to debug and profile parallel applications in Visual Studio 2010.
This is a long time coming...
To have some material, such as SAMPLES and 'accessable' reading matter available to other-than-Master-Jedi-programmers, the black art of parallel programming will seem less arcane and, with hope, more natural.
Full-features languages like C# and rather (for now) escoteric languages like F# are in the right place to exploit parallelism. And the .NET platform is widely used, robust and getting better with each release (and, no, I'm not a Microsoft bigot!)
Machines with multiple cores are the norm. In 5 years, how many cores and how much memory will be on 'standard' desktops? 16 cores? 128 gig? Imagine the tasks deemed impractical today because of resource limitations will be implemented!
It's a great time to be in this business...
Craig Motlin Sep 01, 2014