Welcome to MSDN Blogs Sign in | Join | Help
What's New in the June 2008 CTP of Parallel Extensions

We've just released a new community technology preview (CTP) of Parallel Extensions to the .NET Framework!  You can download it from http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3.  This release contains a plethora of bug fixes as well as some design changes to address some great feedback from you (note that there are some other changes you've requested and that we're planning to make in future releases, so stay tuned).  It also contains a wealth of new functionality, some under the covers, some exposed through new APIs.

Task Parallel Library

The December 2007 CTP included an implementation of the Task Parallel Library (TPL) built on top of a prototype scheduler. As we’ve moved forward with Parallel Extensions, we’ve replaced this prototype with a new scheduler that is built from the ground up to be more robust, efficient, and scalable. The scheduler uses cooperative scheduling and work-stealing to achieve fast, efficient scheduling and maximum CPU utilization. The June 2008 CTP of Parallel Extensions includes this new scheduler, with TPL running on top of it.
While lots of work has been done with the internals of TPL, new functionality has also been exposed through its APIs. A new continuation model has been added to the System.Threading.Tasks.Task and System.Threading.Tasks.Future<T> classes through a new set of ContinueWith methods on both Task and Future<T>, enabling new tasks to be scheduled when previous tasks complete. This is especially powerful for Future<T>, where the continuations are provided with the completed Future<T> and thus with access to its Value, enabling dataflow-oriented solutions, e.g.:

var futureC = Future.Create(() => A()).
ContinueWith(a => B(a.Value)).
ContinueWith(b => C(b.Value));

Continuations can be scheduled to run under a variety of circumstances, such as when a task completes due to an unhandled exception.

Other new functionality includes a new set of WaitAny methods on Task that serve as counterparts to Task’s WaitAll methods (TaskCoordinator, which existed in the December 2007 CTP as the base class for Task and which exposed the WaitAll methods, has been removed). WaitAny enables a developer to wait for any one of a set of tasks to complete, which can be useful for a variety of scenarios, including speculative execution. Consider a problem where multiple heuristics can be used to solve the problem, but it’s not known a priori which algorithm will solve the problem the fastest. If it’s not feasible to parallelize each of the algorithms, the algorithms could all be run in parallel with one another, and the developer can use WaitAny to wait for the first algorithm to complete, e.g.:

var algorithms = new[] {
    Future.Create(() => Alg1()) ,
    Future.Create(() => Alg2()) ,
    Future.Create(() => Alg3()) ,
    Future.Create(() => Alg4()) };
var result = algorithms[Task.WaitAny(algorithms)].Value;

Several new properties have emerged on the Task class. The Name property that appeared in the December 2007 CTP has been replaced by an Id property, and a Creator property has been added. Creator returns the Task that was current when the Task was created. Creator is similar but is not always identical to the Parent property. New in this CTP is an improved notion of task hierarchies and relationships between parent and child tasks. By default, a Task is parented to the Task that was current when it was created; in this case, both Parent and Creator will return the same Task instance. However, Tasks can be created detached from their creator (by specifying the TaskCreationOptions.Detached value), in which case Parent will return null. This is an important capability, because now by default parent tasks implicitly wait on their children before completing, enabling a more structured form of task parallelism and aiding in a developer’s ability to write a correct, task-based application.

A variety of additional and minor API changes have also surfaced in this CTP. The TaskManagerPolicy class contains new values, representing concepts such as the minimum number of processors to use, the ideal number of processors to use, the ideal number of threads to use per processor, the stack size to use per thread, and the thread priority to assign to threads. At a higher-level, the Parallel.Do method has been renamed to Parallel.Invoke. Significant effort has also been invested in fixing bugs in functionality.

PLINQ

The most important changes in this CTP are implementation details for improving the reliability and debuggability of PLINQ. One such change: whereas PLINQ in the December 2007 CTP release was built on top of the .NET ThreadPool, PLINQ in this CTP is now built on top of the Task Parallel Library. Note, however, that this implementation is minimalistic. The plan is for future releases to take advantage of more of the functionality the Task Parallel Library has to offer.

In addition to implementation changes, new APIs are present in this CTP. First and foremost, the APIs for specifying order-preservation have been revamped. In the previous CTP, order-preservation was enabled on a query using the ParallelQueryOptions enumeration, such as in this example written in Visual Basic:

Public Shared Function Scramble(ByVal words As String()) As String()
    Return (From word In words.AsParallel(ParallelQueryOptions.PreserveOrdering) _
               Select ScrambleWord(word)).ToArray()
End Function

The ParallelQueryOptions enumeration has been removed from the API set, and has been replaced by a new AsOrdered extension method, which can be used as follows:

Public Shared Function Scramble(ByVal words As String()) As String()
    Return (From word In words.AsParallel().AsOrdered() _
               Select ScrambleWord(word)).ToArray()
End Function

An AsUnordered extension method also exists to enable the introduction of “shuffle points” into a query. If a certain portion of a query must be processed with a specific ordering, AsOrdered or OrderBy can be used to ensure that ordering is preserved, while AsUnordered can be used to in effect turn off ordering for portions of the query where performance is more important than ordering.

Other API level changes include the introduction of a new extension method, Zip:

public static IParallelEnumerable<TResult> 
Zip<TFirst, TSecond, TResult>( this IParallelEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector);

Zip “zips together” two enumerables, creating a pairing of an item from each enumeration that is then passed to a function. An enumerable containing the results of that function is returned. This CTP also includes a parallel implementation of the SequenceEquals extension method, which was omitted from the previous CTP. Additionally, the Cast and OfType operators have been updated to conform to a breaking change in LINQ-to-Object’s implementation of these operators that’s available in the .NET Framework 3.5 SP1 (more information about this change is available at http://blogs.msdn.com/ed_maurer/archive/2008/02/16/breaking-change-in-linq-queries-using-explicitly-typed-range-variables.aspx).

Coordination Data Structures

The June 2008 CTP introduces a set of coordination data structures that complement PLINQ and the Task Parallel Library. The System.Threading namespace of the .NET Framework 3.5 already contains a handful of synchronization primitives, such as events, monitors, and mutexes, which are low-level constructs useful in developing multithreaded applications. Many parallel applications, however, would benefit greatly from higher-level constructs such as thread-safe collections, more sophisticated locking primitives, data structures to facilitate work exchange, and types that control how variables are initialized. Parallel Extensions adds a plethora of such constructs to the System.Threading and System.Threading.Collections namespaces. The types included in this CTP are:

  • System.Threading.CountdownEvent
  • System.Threading.LazyInit<T>
  • System.Threading.ManualResetEventSlim
  • System.Threading.SemaphoreSlim
  • System.Threading.SpinLock
  • System.Threading.SpinWait
  • System.Threading.WriteOnce<T>
  • System.Threading.Collections.BlockingCollection<T>
  • System.Threading.Collections.ConcurrentQueue<T>
  • System.Threading.Collections.ConcurrentStack<T>
Posted: Monday, June 02, 2008 8:45 AM by toub

Comments

rkpatrick said:

Minor quibble, but shouldn't it be "Task.ID" instead of "Task.Id"?

# June 2, 2008 12:25 PM

Just Code - Tamir Khason said:

Today, Parallel Programming team released 2nd CTP for Parallel Extensions to .NET Framework 3.5. Major

# June 2, 2008 1:32 PM

Just code - Tamir Khason said:

Today, Parallel Programming team released 2nd CTP for Parallel Extensions to .NET Framework 3.5. Major

# June 2, 2008 1:32 PM

It's Spann, not spam said:

Download the Parallel Extensions June 2008 CTP Parallel Extensions simplifies development by providing

# June 2, 2008 2:32 PM

MVPs en Latinoamerica said:

Hola Amigos Este es un excelente recurso, del cual yo se que muchos ya lo habían esperado, aqui les dejo

# June 2, 2008 4:16 PM

LA.NET [EN] said:

The Parallel Extensions CTP is out . It seems like now the PLINQ does no longer depends on the Thread

# June 2, 2008 6:08 PM

Adityanand Pasumarthi said:

The "Task Prallel Library" is shaping up exactly as my "Managed IOCP" & "Asynchronous Code Blocks" with features like Managed scheduler, continuations, etc, which I created 2 years back.

Take a look at them here on CodeProject.

http://www.codeproject.com/KB/cs/AsynchronousCodeBlocks.aspx

Regards,

Aditya.P

# June 2, 2008 6:16 PM

Magnus Markling said:

Hi!

I just downloaded and tried to install the CTP today. When the progress bar was finished I got a series of error dialogs saying (in order):

"Could not create WScript.Shell"

""

"-2147024770"

"Could not start browser"

"Object required"

"424"

Then the installer existed with no further information. Everything seems to be properly installed though, and System.Threading is GACed.

Regards

Magnus

# June 2, 2008 6:22 PM

ASPInsiders said:

The Parallel Extensions CTP is out . It seems like now the PLINQ does no longer depends on the Thread

# June 2, 2008 6:52 PM

Jon Skeet: Coding Blog said:

Either my timing is great or it&#39;s lousy - you decide. Yesterday I posted about parallelising Conway&#39;s

# June 2, 2008 6:56 PM

Community and Influencers Blog said:

At Microsoft we are always looking to get feedback about our products and technologies from communities

# June 2, 2008 7:45 PM

Nick MacKechnie said:

Hi All, Parallel Extensions simplifies development by providing library-based support for introducing

# June 2, 2008 9:01 PM

Carl said:

Keep it up.  You are headed in not only the right direction, but something very much needed.

Thanks!

# June 3, 2008 12:28 AM

bkchung's WebLog said:

Parallel Programming with .NET : Released! Parallel Extensions to the .NET Framework June 2008 CTP .NET

# June 3, 2008 2:01 AM

toub said:

rkpatrick: Thanks for the suggestion.  "ID" isn't an acronym, but rather is an abbreviation (for identification or identifier), so it's called out in the .NET Framework naming guidelines as "Id" instead of as "ID".  For more information, see http://msdn.microsoft.com/en-us/library/ms182256(VS.80).aspx.

Magnus: Sorry for the install troubles, but it sounds like you're up and running.  I believe WScript.Shell is just used to launch the readme after everything has been installed, so you should be fine.

Carl: Thanks!  Great to hear.  Please let us know your thoughts and suggestions moving forward.

# June 3, 2008 2:48 AM

Luís Lopes said:

Está disponível para download a CTP 2008 da Parallel Extensions...

# June 3, 2008 6:36 AM

Марат Бакиров [MS] said:

Вышел второй CTP для Parallel Extensions - библиотеки позволяющей облегчить напи

# June 3, 2008 7:28 AM

rkpatrick said:

toub: Wow, I used to change all my Id's over to ID to stay consistent with the BCL, and I could have sworn I read blog discussions about why ID is a special case to be kept as "ID" but going back to brada's posts, you are correct in that it's now "Id". I need to go back and read the Framework Guidelines book when I get home, because I've apparently forgotten some pretty core conventions...not to mention I haven't run FxCop since pre-1.35

# June 3, 2008 11:55 AM

Public Sector Developer Weblog said:

Free performance lunch is over. During the past few decades we witnessed continuous growth of single

# June 3, 2008 12:17 PM

Me about things... said:

On top of Bill Gates announcements at the Microsoft Tech·Ed North America 2008 Developers conference,

# June 3, 2008 1:34 PM

Parallel Programming with .NET said:

The June 2008 Community Technology Preview (CTP) of Parallel Extensions to the .NET Framework was released

# June 5, 2008 1:50 AM

Jeremiah Clark's Blog said:

The Parallel Programming team has released a June 2008 CTP of the Parallel Extensions for .NET. They

# June 5, 2008 1:40 PM

Paul Mooney said:

Parallel Extensions June 2008 CTP ReleasedThe Parallel Programming team has released a June 2008 CTP...

# June 5, 2008 2:23 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker