Parallel Computing: Leverage the better hardware tomorrow

It has quite a sometime we have been using .NET with System.Threading namespace. So what is new there in Parallel Computing in .NET Framework 4.0 with Visual Studio 2010. There are a lot

Ø Task-based fine grained parallelism

Ø Better debugger feature

Ø Structured Parallelism

Ø Declarative Parallelism

Above all you are getting yourself ready for better tomorrow. Why one should be using fine-grained parallelism not the classic Threading? I feel

Ø Threading still is with OS’s ownership

Ø Very much dependent on number of CPSs. Reason why it is, if you have more Threads than the number of CPUs it will have more context switches. Each Thread requires 1 MB dedicated memory. So more Threads more dedicated memory.

So what is special there in the Task class?

Ø It creates small pieces of work and distributes the work across the CPUs. More CPUs more distribution. Less CPU – no harm.

Ø It has a concept of work-stealing. What that means?

o With the improved CLR Thread Pool it works just like thread. It first creates work in Global Queue. Then passes them to all Worker Processes Local Queue. Till this time it has no difference from System.Threading.

o Now all the Local queue will create there sub Tasks and keeps on working. If one of the Worker Processes is empty they will not sit idle, they will steal the task from others local Queue.

o As well when it passes Task to other Worker Process does not give the last one which is fresh in CPU. Always give the first one so that not enough context switching will not happen.

I will be writing few post on Parallel Computing – keep watching and Happy Weekend.