Friday, February 1, 2008

Multicores, the developer dilemma and Microsoft PFX

Thanks to Moores law developers never had to worry about how their application would perform with newer processors, with every newer-faster processor in the market their application 'automagically' just ran faster. This is all set to change Moores law will no longer apply to processors - adding more transistors to a processor is not feasible anymore since doing so is heating up the processor hence most of the processor manufacturers like Intel, AMD and IBM are going for multi core processor architecture. ie now individual processors will not have radically improved performance, high performance can be acheived by leveraging the multicores of the processor. Leveraging different cores on the processor is a challenge developers never had to face in the past.

So how do we write code that take advantage of multicores? Fortunately application servers like Microsoft IIS and SQL Server already ship with support for multicore but how can our applications leverage it? Relying on the developers to write code optimized for multicore would be too much to ask, the good folks at Microsoft are working on a framework (for managed code) that can greatly enhance developer productivity when targeting multicore systems. The framework is called the .NET PFX , the December 2007 CTP can be downloaded from here.
What do you do when you have an 8 core server around at your disposal … run PFX of course :) … beats running it off my dual core laptop. Have created a simple project that simulates computation work via 2 for loops, later the outer for loop was changed to a Parallel.For (new set of features in the PFX available in the System.Threading namespace)

The results are as follows:

When running the basic nested loop the overall operation takes 11792 milliseconds and as can be seen in the figure below only one core is being leveraged (behind the scene only one thread is being used)




When the same code is run using the PFX the same set of operations take 1746 milliseconds ie almost 1/10th the time taken in the previous case and as can be seen in the figure multiple cores are being used to complete the task (behind the scene multiple threads are being used)



This post demonstrates a simple case where the PFX can be used, in the future post we will take a look at using PFX (and PLINQ) to build more complex applications.

0 comments:

Post a Comment