c# Environment.ProcessorCount does not always return the full number of Logical Processor, why?

大兔子大兔子 提交于 2019-11-30 13:22:29

There may be a hint in the docs:

"If the current machine contains multiple processor groups, this property returns the number of logical processors that are available for use by the common language runtime (CLR)."

Could that be the issue here?

MSDN Article

Found something else interesting:

By default, the pool is restricted to a single processor group (http://msdn.microsoft.com/en-us/library/windows/desktop/dd405503(v=vs.85).aspx), and thus to 64 cores. However, in .NET 4.5 you can set the Thread_UseAllCpuGroups enabled="true" flag.

MSDN Forum Post

According to the MSDN docs on <Thread_UseAllCpuGroups> you need to set up the following to have all the CPU groups seen and used:

<configuration>
   <runtime>
      <Thread_UseAllCpuGroups enabled="true"/>
      <GCCpuGroup enabled="true"/>
      <gcServer enabled="true"/>
   </runtime>
</configuration>

Check your system NUMBER_OF_PROCESSORS environment variable. That's what method returns. See MSDN article: http://msdn.microsoft.com/en-us/library/system.environment.processorcount%28v=vs.100%29.aspx (permission section).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!