PLINQ:并行扩展会自动处理单核和多核环境吗? [英] PLINQ: Will Parallel Extensions automatically handle single and multi-core environments?

查看:78
本文介绍了PLINQ:并行扩展会自动处理单核和多核环境吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LINQ的并行扩展会自动检测内核数量并全部利用吗?相反,如果代码在单核计算机上运行,​​它仍然可以工作,还是我必须检测核的数量并告诉PLINQ要运行多少个核?

Will LINQ's parallel extensions automatically detect the number of cores and utilize them all? Conversely, if the code is run on a single core machine, will it still work or do I have to detect the number of cores and tell PLINQ how many to run across?

不幸的是,我无法使用任何单核计算机来测试我的代码,所以我什至无法自己测试,而且我无法可以在其他地方找到任何有用的信息...

Sadly, I don't have access to any single core machines to test my code on so I can't even test this for myself and I haven't been able to find any useful info elsewhere...

虽然乍一看何时应该使用并行性,但关于在何处应该使用并行化方面有任何经验法则重要的是不应该使用 吗?

Also, while it might at first seem obvious when to use parallelism, are there any rules of thumb regarding where it should and as importantly should not be used?

侧面注意:我不一定要在特定的环境中编程。我倾向于根据手头的任务在网络,客户端/服务器应用程序,Windows应用程序,Windows服务,控制台服务和控制台实用程序之间平均分配时间(取决于项目)。

Side Note: I don't necessarily program in a specific environment. I tend to divide my time somewhat equally (depending on project) between web, client/server apps, windows apps, windows service and console utilities depending on the task at hand.

推荐答案

是的,它可以自行处理内核计数,并且在单核,伪多核(HT)上运行良好,最多可以达到愚蠢的内核数量-但您确实需要编写代码对抗 Parallel 自己;

Yes, it handles the core count itself, and is fine on single core, pseudo-multi-core (HT), right up to stupid numbers of cores - but you do need to code against Parallel yourself; it doesn't simply seize control over your existing code.

对于何时使用并行机制...这是巨大的主题。实际上,如果您正在执行Web编程-我会忘记它,而只是让IIS对不同的请求使用不同的并行线程(而不是让一个请求占用计算机)。

For when to use parallelism... that is a huge topic. Actually, if you are doing web programming - I'd forget it and simply let IIS use different parallel threads for different requests (rather than letting one request hog the machine).

它主要用于大型数据处理/数据收集-在专用的应用程序服务器上或在客户端。

It is mainly useful for big number crunching / data gathering - either on a dedicated app-server, or at the client.

这篇关于PLINQ:并行扩展会自动处理单核和多核环境吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆