是有可能限制磁芯Parallel.ForEach? [英] Is it possible to limit the cores for Parallel.ForEach?

查看:219
本文介绍了是有可能限制磁芯Parallel.ForEach?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的code使用 Parallel.ForEach 。我所有的8个内核到100%。这是坏的是在服务器上运行的其他应用程序。 是否有可能限制执行喜欢4核?

I'm using a Parallel.ForEach in my code. All my 8 cores go to 100%. This is bad for the other apps that are running on the server. Is it possible to limit execution to like 4 cores?

推荐答案

传递的 ParallelOptions 的实例与 ParallelOptions.MaxDegreeOfParallelism 设置为4〜 Parallel.ForEach

Pass an instance of ParallelOptions with ParallelOptions.MaxDegreeOfParallelism set to 4 to Parallel.ForEach.

不过,这可能不会对其他机器某种意义上说,这可能比你更多或更少的核心。一般来说,你应该让框架决定的并行度。

Nevertheless this might not make sense on other machines, that might have more or less cores than you. In general you should let the framework decide the degree of parallelism.

这篇关于是有可能限制磁芯Parallel.ForEach?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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