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.