Posted By: Charles | Oct 12th, 2007 @ 10:21 AM
Microsoft is developing a number of technologies to simplify the expression of parallelism in code. An example of this work is Parallel Extensions for the .NET Framework (PFX), a managed programming model for data parallelism, task parallelism, scheduling, and coordination on parallel hardware.

PFX makes it easier for developers to write programs that take advantage of parallel hardware (you've all heard of multi-core and what the future holds with many-core...), without having to deal with the complexities of threads and locks in today’s concurrent programming story. Of course, PFX is not a concurrent programming silver bullet. There is still a great deal of work left to do in the imperative programming world's approach to concurrency. PFX is an excellent start with a syntax that .NET developers can relate to and understand.

Here, Joe Duffy, Senior Software Engineer, and Technical Fellow Anders Hejlsberg sit down with me to discuss the basics and some of the details of the managed PFX library's architecture and implementation, whiteboard included.

For more information on specific technologies, check out the PLINQ and TPL articles in the October 2007 issue of MSDN Magazine.


High res video download file here.
Rating:
0
0
PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman
Is the Task Parallel Lib built on the 2.0 CLR, wasn't clear to me if it's a pure .net assembly, or if it needs changes to and is intergrated with the CLR.

Can anyone answer the question of how PFX relates to the Concurrency and Coordination Runtime (CCR) that ships with the MS robotics studio?

Anthony
Glucose
Glucose
Scott Hanselman
Great stuff! This is going to be a fun technology. Also check out a podcast interview with Stephen Toub, another member of the team.

--
Scott Hanselman
littleguru
littleguru
allein, allein,... allein, allein!
I have some questions. Let's have this simple call:

Parallel.For(0, count, i => a(i));

I would like to know how you guys make sure that function a(i) isn't calling a x(...) that relies on a global variable (like a singleton). How are you checking that? Isn't that checked at all - is it up to the dev to check that? I can see a lot of people saying: "my code worked and now it isn't working anymore, damn PFX library. It killed it!" instead of checking out there code for possible "side effects".

Are there papers or docs around that you used for your for global variables and shared resources checks?

I liked it when we got into the more "geeky" part... the thing about what item is picked from the queue etc. Would have been nicer if we would have gotten more about that stuff - speaking of the "geeky" stuff.

But it was a very nice video! Thanks for your time guys.
ktr
ktr
two sides to everything
wow that is very impressive. i'm really stunned that it is that easy now. multiple threads optimized for core count, plus work stealing and all those awesome feautures essentially for free! too cool.

are there any plans to integrate this library into the actual language going into the future? that would be very cool.

maybe like:

parallel for (int i = 0; i < 10; i++)
    // do something

that would feel very natural, and i don't think it would be that much of a leap. LINQ queries should be automatically implemented as parallel, just because of the nature of a query - there should be no expectation of sequentiality.
amotif
amotif
No Silver Bullet

Good video.

littleguru wrote:
I would like to know how you guys make sure that function a(i) isn't calling a x(...) that relies on a global variable (like a singleton).


That's an interesting thought. I have no particular insight into the answer, but I'm guessing it would be quite difficult to implement due to at least a couple reasons:

a) To generalize your question (correctly, I hope), it's not just globals that are a concern, it's any shared state--is your lambda expression using shared state in a thread-safe fashion? Here's a simple non-global example:

    R r = new R();
    Parallel.For(0, 1000, 
        i => {
            int v = r.Next(1, 6);
            ...
        });

Here we have N threads accessing r. How do you determine whether r is being used in a thread-safe manner? If you know that class R is not thread-safe, then this code isn't either. But how would a compiler or runtime determine whether this is safe, through static or run-time analysis of all the possible code paths? This seems to me to be a rather difficult problem.

b) Aside from the difficultly of analyzing the code, how do you define what's "correct?" If I substitute a thread-safe class for R how would you now determine that the use of r is now thread-safe? Perhaps analysis would show the use of a locking mechanism? What if the new class is written using a lockless technique, how would you determine whether it's safe or not?

As mentioned in the video some problems require shared state and some problems don't. For example, consider applying update operations to a graph in parallel. Shared state isn't a side effect here; in fact, the whole point is to update shared state. How would analysis take that into account?

It's an interesting thought, though. Smiley

esoteric
esoteric
IExplode.exe no more

I assume there is a reason why you have to explicitly say you want your code parallelized. It's still an imperative world with islands of declarativeness. But I assume that in the future the compiler or CLR will auto-parallelize some code, where it can determine the safety of it.

But the team has its priorities right. It first creates the foundation for parallelism. Then later it can start to think about (or someone else can) the cases that are safe to parallelize - and where it makes sense to do so.

Maybe, with all the threads running on the machine, it wouldn't make sense to parallize some tasks, even though it would be possible to do so.

Just a thought...

One thing is for sure. The C#/CLR team has a great understanding of how to maximize impact and value whilst keeping disruption minimal.

One thing I didn't pick up from the video - is the Parallel Task Lib built on top of the existing Thread Pool stuff?

Another great video.

littleguru
littleguru
allein, allein,... allein, allein!
amotif wrote:
a) To generalize your question (correctly, I hope), it's not just globals that are a concern, it's any shared state--is your lambda expression using shared state in a thread-safe fashion?


Yeah. I just picked one case (the singleton) because it's always the same domain of problems... But how you generalized the question is exactly what I had in mind...

I can't really think that static checks (or even runtime checks) are implemented... Such checks could really take very long and could possibly include a big part of the application that is compiled.

Static check would also need to be implemented in a sort of compiler task or in the compiler itself, which isn't that cool if you have a library that possibly targets n compilers. How do you make sure that all the compilers call that task or do the checks on their own?
ktr wrote:
parallel for (int i = 0; i < 10; i++)
    // do something

The way they're doing parallel for is better.  The way you've suggested serializes access to i unnecessarily.