I'm trying to determine how AsParallel() splits it's 'source', and indeed what is meant by 'source'...
For example...
public class CSVItem
{
public DateTime Date { get; set; }
public string AccountNumber { get; set; }
}
List<CSVItem> CSVItemList = new List<CSVItem>();
Then put 500k varying CSVItem's into CSVItemList.
Then use:
CSVItemList = CSVItemList.AsParallel().OrderBy(x => x.AccountNumber).ThenBy(q => q.Date).ToList();
Will it only split the 'source' (meaning for example 250k records onto each of two threads) onto multiple asynch threads and perform the OrderBy().ThenBy() on each thread then merge the results...
Or will it separate the OrderBy() and ThenBy() onto separate threads and run them and then merge the results... giving a strangely ordered list?
It gose one by one a) done with
OrderBy
merge result and than gose for b)ThenBy
. Below image form Albahari blog shows how it works i.e. it take one by oneQ: how many number of task
A : you can decide this by using
WithDegreeOfParallelism
forces PLINQ to run the specified number of tasks simultaneouslyCheck this : Parallel Programming
I created a little example to check, which one is true.
Result
AsParallel() does what we want. It first processes the OrderBy() parallel, merges back the list and then moves on to the next query, in our case ThenBy().