by default, will plinq use range partitioning or chunk partitioning for Dictionary<string, string>? and how to force the other?

744 Views Asked by At

By default, will plinq use range partitioning or chunk partitioning for a Dictionary<string, string>?

This is my use case:

    Dictionary<string,string> asmachtas = new Dictionary<string,string>();
    ...
    int sum = asmachtas.AsParallel().Sum(arg => myFunction(arg));

How can I check this myself? How can I force the other type of partitioning?

2

There are 2 best solutions below

1
Igor ostrovsky On BEST ANSWER

Range partitioning only applies to collections that implement IList<>. Dictionary<,> only implements IEnumerable<> and not IList<>, so chunk partitioning would be used.

The partitioning algorithm used by PLINQ is an implementation detail, so you don't really have a way to look it up. You could put a breakpoint into the delegate passed into Sum() and deduce the partitioning scheme from the call stacks, but the stacks are rather messy.

0
Ronny Karlsson On

As Igor said, the query would be using chunk partitioning.

I'd like to add that converting it asmachtas.ToList().AsParallel() would make it use range partitioning. Or if you were working with a list you can create a chunk-partitioner with Partitioner.Create(asmachtas, true).