默认情况下,plinq 会对 Dictionary使用范围分区还是块分区?以及如何强迫对方?
默认情况下,plinq 会对 Dictionary
使用范围分区还是块分区?
这是我的用例:
Dictionary<string,string> asmachtas = new Dictionary<string,string>();
...
int sum = asmachtas.AsParallel().Sum(arg => myFunction(arg));
我如何自己检查?如何强制进行其他类型的分区?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
范围分区仅适用于实现 IList<> 的集合。字典<,>仅实现 IEnumerable<>;而不是 IList<>,因此将使用块分区。
PLINQ 使用的分区算法是一个实现细节,因此您实际上没有办法查找它。您可以在传递给 Sum() 的委托中放置一个断点,并从调用堆栈中推断出分区方案,但堆栈相当混乱。
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.
正如 Igor 所说,查询将使用块分区。
我想补充一点,转换它
asmachtas.ToList().AsParallel()
会使其使用范围分区。或者,如果您正在使用列表,则可以使用Partitioner.Create(asmachtas, true)
创建块分区器。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 withPartitioner.Create(asmachtas, true)
.