PLINQ 到底是什么?
PLINQ 作为 LINQ 的扩展添加到 .NET 4.0 Framework 中。
- 它是什么?
- 它解决什么问题?
- 什么时候合适,什么时候不合适?
PLINQ was added in the .NET 4.0 Framework as an extension to LINQ.
- What is it?
- What problems does it solve?
- When is it appropriate and when not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这就是并行 LINQ。这是一种在多核/多处理器系统上并行运行 LINQ 查询的方法,以便(希望)加快它们的速度。
MSDN 杂志中有一篇关于此的好文章。
有关当前详细信息和计划,我建议阅读使用 .NET 团队进行并行编程博客上的文章。他们是实现并行扩展的团队,包括 PLINQ。
This is Parallel LINQ. It's a way to run LINQ queries in parallel on multi-core/multi-processor systems, in order to (hopefully) speed them up.
There is a good article on this in MSDN Magazine.
For current details and plans, I recommend reading articles on the Parallel Programming with .NET Team Blog. They are the team implementing the parallel extensions, including PLINQ.
PLINQ 是并行执行的 LINQ,即使用当前计算机中尽可能多的处理能力。
如果您有一台具有 2 个内核(例如双核处理器)的计算机,您将让语言集成查询运算符使用两个内核并行完成工作。
“仅”使用 LINQ 您不会获得那么多的性能,因为标准语言集成查询运算符不会并行化您的代码。这意味着您的代码将以串行方式运行,而不利用所有可用的处理器内核。
有许多 PLINQ 查询运算符能够使用众所周知的并行模式执行代码。
请查看我的博客文章,其中我展示了使用 AsParallel 扩展方法并行运行简单 LINQ 查询时获得的速度:
使用 Visual Studio 2010/2012 的并行 LINQ (PLINQ) - 性能测试
如果您想深入使用 PLINQ,我建议您阅读:
并行编程模式:使用 .NET Framework 4 理解和应用并行模式
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
它是一个库,允许您采用普通的 LINQ 查询,将其划分为较小的任务,并利用处理器核心在多个线程上执行每个单独的任务。
It is a library that allows you to take a normal LINQ query, divide it into smaller tasks and execute each individual task on multiple threads taking advantage of processor cores.
它允许您将 .AsParallel 添加到 LINQ 以尝试使用尽可能多的处理器执行查询。很简单,但您仍然需要了解一些关于您的算法是否“可并行”的信息 - 这并不神奇。
它基本上消除了管理线程池的需要,并管理同步从每个线程返回的结果 - 通常如果没有并行扩展库,您将必须手动执行此操作。
It allows you to add .AsParallel to your LINQ to attempt to execute the query using as many processors as possible. Neat, but you still need to know a bit about whether your algorithm is "parallelisable" - it isn't magic.
It basically removes the need to manage a thread pool and manages synchronising the results coming back from each thread - normally without the parallel extensions library you would have to do this manually.
来自维基百科的并行扩展:
From Wikipedia's Parallel Extensions: