“令人愉快的平行” PLINQ 查询
此示例来自 PLINQ MSDN 文章:
http://msdn.microsoft.com/ en-us/library/dd997399.aspx
var queryA = from num in numberList.AsParallel()
select ExpensiveFunction(num); //good for PLINQ
var queryB = from num in numberList.AsParallel()
where num % 2 > 0
select num; //not as good for PLINQ
为什么 queryB 不被认为是“令人愉快的并行”?看起来这对于在多个线程上分割是理想的,因为列表中的每个元素都是独立于其他元素的。
This example is from the PLINQ MSDN article:
http://msdn.microsoft.com/en-us/library/dd997399.aspx
var queryA = from num in numberList.AsParallel()
select ExpensiveFunction(num); //good for PLINQ
var queryB = from num in numberList.AsParallel()
where num % 2 > 0
select num; //not as good for PLINQ
Why isn't queryB considered 'delightfully parallel'? It seems like this would be ideal to split on multiple threads because each of the elements in the list is independent of the others.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第二个示例不适合并行化的原因很简单,因为将工作拆分到多个线程上所产生的开销通常很高,因此并行完成的工作必须超过该开销。廉价的手术并不是一个好的选择。
The reason why the second example isn't a good candidate for paralellization is simply because the overhead incurred in splitting the work up over multiple threads is generally high, so the work done in parallel would have to outweigh that overhead. An inexpensive operation is not a good candidate.