“令人愉快的平行” PLINQ 查询

发布于 2025-01-02 02:51:32 字数 506 浏览 1 评论 0原文

此示例来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北音执念 2025-01-09 02:51:32

第二个示例不适合并行化的原因很简单,因为将工作拆分到多个线程上所产生的开销通常很高,因此并行完成的工作必须超过该开销。廉价的手术并不是一个好的选择。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文