Channels ▼

Gastón Hillar

Dr. Dobb's Bloggers

.NET 4 Parallel Extensions Also Have Powerful Extras

May 06, 2010

.NET 4 offers dozens of new classes, structures and enumerations to support many common parallelism scenarios. However, there are some additional scenarios not covered in the base classes that compose Parallel Extensions.

If you face one of these scenarios in which you have to make either simple or complex customizations to tailor the base classes to tackle certain specific requirements, be sure to check the scenarios covered by the new Parallel Extensions Extras.

.NET Framework 4 includes the new Parallel Extensions. They offer the new task-based programming model, PLINQ (short for "Parallel Language Integrated Query") and many other features to tackle the multicore and manycore revolution.

Parallel Extensions Extras is a complementary project that isn't part of the .NET 4 classes but it has been developed by Microsoft. As these extras include the source code, you can also tailor them for your specific needs. The extras are a bit hidden because they are included in one of the projects within the Parallel Extension Samples. The direct link to download its recently updated latest version is http://code.msdn.microsoft.com/ParExtSamples/Release/ProjectReleases.aspx?ReleaseId=4179. So, if you download these samples for parallel programming with .NET 4, you can find and inspect the "ParallelExtensionExtras" project that contains all the extras organized in many folders, as in the next picture that displays the contents for this project in Visual Studio 2010 Solution Explorer.

Figure 1: The contents of the ParallelExtensionExtras projects in the Solution Explorer. Lots of exciting classes to inspect, organized in many folders.

A typical situation that usually needs a customized scheduler is when you want to use many tasks to run a pipeline. Each task represents a stage for the pipeline and you want to make sure that the task scheduler dedicates a thread to support the execution of each task. To do so, you can use the ThreadPerTaskScheduler class, included in the ParallelExtensionExtras project. This class is a subclass of System.Threading.Tasks.TaskScheduler and provides a task scheduler that dedicates a thread per task. It simply starts a new thread to process the provided task. Thus, you can create the tasks that will compose each stage of the pipeline with the necessary parameters to specify this customized scheduler. The ThreadPerTaskScheduler class is one of the nine customized task schedulers provided by Parallel Extensions Extras.

One of my surprises with Parallel Extensions was the lack of a class to support pipelined data processing. Pipelines are pretty popular in many other parallel programming extensions or APIs. Luckily, Parallel Extension Extras include a Pipeline class where each stage runs in a different thread by using the aforementioned ThreadPerTaskScheduler. The Pipeline class is useful when you want to start working with pipelines and you want to take advantage of .NET 4 new features. It provides a basic infrastructure and you can add each new stage or filter with just a few lines of code.

There are many other additional examples and these classes are worth a deeper analysis with complete examples of how to take advantage of them. In future posts, I'll explain samples that cover their usage. Parallel Extensions Extras groups the classes in the following categories:

  • Coordination data structures in the "CoordinationDataStructures" folder.
  • Drawing in the "Drawing" folder.
  • Extensions in the "Extensions" folder.
  • Parallel algorithms in the "ParallelAlgorithms" folder.
  • Partitioners in the "Partitioners" folder.
  • Task schedulers in the "TaskSchedulers" folder.
  • Utils in the "Utils" folder.

Whenever you have to solve a problem that involves parallelism in .NET 4; if you don't find a suitable class in Parallel Extensions, be sure to check whether there is a class that can help you within Parallel Extension Extras. Each category deserves a deep review. My next post will talk about the different task schedulers offered by Parallel Extension Extras in the "TaskSchedulers" folder.


For more on .NET 4's support for parallelism, see Custom Parallel Partitioning With .NET 4 and Visual Studio 2010 Brings Parallelism Mainstream.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video