Introduction
This is the 4th part of my proposed series of articles on TPL. Last time I introduced Parallel For and Foreach, and covered this ground:
Parallel For/Foreach
Creating A Simple Parallel For/Foreach
Breaking And Stopping A Parallel Loop
Handling Exceptions
Cancelling A Parallel Loop
Partioning For Better Perfomance
Using Thread Local Storage
This time we are going to be looking at how to use Parallel LINQ, or PLINQ as it is better known. We shall also be looking at how to do the usual TPL like things such as Cancelling and dealing with Exceptions, as well as that we shall also look at how to use custom Partionining and custom Aggregates.
Article Series Roadmap
This is article 4 of a possible 6, which I hope people will like. Shown below is the rough outline of what I would like to cover.
Starting Tasks / Trigger Operations / ExceptionHandling / Cancelling / UI Synchronization
Continuations / Cancelling Chained Tasks
Parallel For / Custom Partioner / Aggregate Operations
Parallel LINQ (this article)
Pipelines
Advanced Scenarios / v.Next For Tasks
Now I am aware that some folk will simply read this article and state that it is similar to what is currently available on MSDN, and I in part agree with that, however there are several reasons I have chosen to still take on the task of writing up these articles, which are as follows:
It will only really be the first couple of articles which show simliar ideas to MSDN, after that I feel the material I will get into will not be on MSDN, and will be the result of some TPL research on my behalf, which I will be outlining in the article(s), so you will benefit from my research which you can just read...Aye, nice
There will be screen shots of live output here which is something MSDN does not have that much off, which may help some readers to reinforce the article(s) text
There may be some readers out here that have never even heard of Task Parallel Library so would not come across it in MSDN, you know the old story, you have to know what you are looking for in the 1st place thing.
I enjoy threading articles, so like doing them, so I did them, will do them, have done them, and continue to do them
All that said, if people having read this article, truly think this is too similar to MSDN (which I still hope it won't be) let me know that as well, and I will try and adjust the upcoming articles to make amends.
Table Of Contents
Anyway what I am going to cover in this article is as follows:
Introduction To PLinq
Useful Extension Methods
Simple PLinq Example
Ordering
Using Ranges
Handling Exceptions
Cancelling A PLinq Query
Partitioning For Possibly Better Perfomance
Using Custom Aggregation
Introduction To PLinq
As most .NET developers are now aware there in inbuilt support for querying data inside of .NET, which is known as Linq (Language Integrated Query AKA Linq), which comes in serveral main flavours, Linq to objects, Linq to SQL/EF and LINQ to XML.
We have all probably grown to love writing things like this in our everyday existense:
(from x in someData where x.SomeCriteria == matchingVariable select x).Count();
Or
(from x in peopleData where x.Age > 50 select x).<span lang="en-gb">ToList</span>();
Which is a valueable addition to the .NET language, I certainly could not get by without my Linq. Thing is the designed of TPL have thought about this and have probably seen a lot of Linq code that simply loops through looking for a certain item, or counts the items where some Predicate<T> is met, or we perform some aggregate such as the normal Linq extension methods Sum(), Average(), Aggregate() etc etc.
Read more: Codeproject
0 comments:
Post a Comment