40

PLINQ 作为 LINQ 的扩展添加到 .NET 4.0 框架中。

  • 它是什么?
  • 它解决了哪些问题?
  • 什么时候合适,什么时候不合适?
4

5 回答 5

36

这是并行 LINQ。这是一种在多核/多处理器系统上并行运行 LINQ 查询的方法,以便(希望)加快它们的速度。

MSDN 杂志上有一篇很好的文章。

有关当前的详细信息和计划,我建议阅读使用 .NET 团队博客进行并行编程的文章。他们是实现并行扩展的团队,包括 PLINQ。

于 2009-11-02T19:05:00.033 回答
15

PLINQ is LINQ executed in Parallel, that is, using as much processing power as you have in your current computer.

If you have a computer with 2 cores like a dual core processor you'll get your Language Integrated Query operators do the work in parallel using both cores.

Using "only" LINQ you won't get as much performance because the standard Language Integrated Query operators won't parallelize your code. That means your code will run in a serial fashion not taking advantage of all your available processor cores.

There are lots of PLINQ query operators capable of executing your code using well known parallel patterns.

Take a look at my blog post in which I show the speed up you get when you run a simple LINQ query in Parallel using the AsParallel extension method:

Parallel LINQ (PLINQ) with Visual Studio 2010/2012 - Perf testing

If you want to go deep using PLINQ, I advise you to read:

Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4

于 2009-11-28T00:05:29.873 回答
10

它是一个库,允许您执行普通的 LINQ 查询,将其划分为较小的任务,并利用处理器内核在多个线程上执行每个单独的任务。

于 2009-11-02T19:05:37.123 回答
3

它允许您将 .AsParallel 添加到 LINQ 以尝试使用尽可能多的处理器执行查询。很好,但你仍然需要知道你的算法是否是“可并行的”——这不是魔法。

它基本上消除了管理线程池的需要并管理同步从每个线程返回的结果 - 通常没有并行扩展库,您必须手动执行此操作。

于 2009-11-02T19:07:03.447 回答
1

来自维基百科的并行扩展

并行 LINQ (PLINQ) 是 LINQ 的并发查询执行引擎,可并行执行对对象 (LINQ to Objects) 和 XML 数据 (LINQ to XML) 的查询。PLINQ 旨在通过使用查询来公开数据并行性。PLINQ 可以并行化已实现为查询的对象上的任何计算。但是,对象需要实现由 PLINQ 本身定义的 IParallelEnumerable 接口。在内部,它使用 TPL 执行。

于 2009-11-02T19:03:13.523 回答