I am very delighted as Visual Studio 2010 has finally released on last 12 April 2010. Now let me continue my Parallel Extension blogs series, but this time in release version of Visual Studio .
In the first post of this series, I illustrated the significance of parallel computing and impact of un-readiness parallel-enabled software. Furthermore, I talked about Task Parallel Library in the second post. In this third post, I’ll talk about PLINQ (parallel version of LINQ). I believe this would be another interesting topic.
To comprehend this post, I assume that the reader is familiar with LINQ (Language Integrated Query). If you are not familiar with LINQ, no worries. The following link will give you a quick start of understanding LINQ:
So, what is PLINQ? It’s just parallel implementation of LINQ. The idea of PLINQ is to enable developer to utilize the multi-core processor hardware effectively, yet retain the capability of LINQ. It is designed to be as usable as possible, thus developer will save the learning curve.
Now, let me give you some code example the comparison of LINQ and PLINQ.
List<int> intList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var query = from i in intList where i % 2 == 0 select i;
List<int> intList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var query = from i in intList.AsParallel() where i % 2 == 0 select i;
Hm… That’s all. So simple? Yes it is. We could just simply put AsParallel() method on the list when we are performing LINQ.
Note that .AsParallel() method is actually an extension method to the collection that implement IEnumerable<T>.
By default, PLINQ uses all of the processors on the host computer up to a maximum of 64. You can instruct PLINQ to use no more than a specified number of processors by using the WithDegreeOfParallelism(Of TSource) method. This is useful when you want to make sure that other processes running on the computer receive a certain amount of CPU time.
List<int> intList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var query = from i in intList.AsParallel().WithDegreeOfParallelism(2) where i % 2 == 0 select i;
In the next post, I’ll talk about the Task Visualization support from IDE. See you!
What we have cover so far? So far in the Parallel Extension series, I’ve talked about: Introduction and