14

On my machine, windows 7 - Enterprise with 1 x Intel Xeon E5-1660 0 @ 3.30Ghz (6 cores/cpu with Hyper Threading activated), Environment.ProcessorCount return 12 which is exact.

On a Windows Server 2012 with 2 x Intel Xeon E5-2697 v3 @ 2.60GHz (14 cores/cpu with Hyper Threading activated(I think because task manager show: 2 sockets, 28 cores, 56 logical processors)), Environment.ProcessorCount return 28 which appears to us as wrong because 2x14x2 = 56.

Why on Windows Server 2012 c# method Environment.ProcessorCount does not return the proper number of logical processors?

As Additional information, environment variables are as follows: NUMBER_OF_PROCESSORS=28

TaskManager

Update 2015-05-26:

There is a more details/reasons of this related bug in my other question: Unable to use more than one processor group for my threads in a C# app. Mainly I think that C# does only use one processor group. What's werid was that on our server, there was 2 processor groups although there was only 56 logical processors. But this HP CUSTOMER ADVISORY explain why our server bios configuration were inducing windows in error.

Community
  • 1
  • 1
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119

3 Answers3

10

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

Doug Dawson
  • 1,254
  • 2
  • 21
  • 37
  • Yes it could be... but that's what I'm looking for. An explanation why the available number is less than the full amount? ... A license problem, a windows setting, windows normal behavior??? – Eric Ouellet Jan 15 '15 at 14:53
  • I wonder if the CLR either doesn't by default, or isn't capable of picking up on a second physical CPU? I'm no expert in this area, but I'm genuinely curious. – user2366842 Jan 15 '15 at 14:53
  • @user2366842, I agree, I wonder if it is the case (I thought it could be), I have no idea, I searched without success the reason why? – Eric Ouellet Jan 15 '15 at 14:54
  • @Doug Dawson, your new found seems really interesting... I will have to test that today. I do not have access to that server directly. I will be back soon with more info on the results (up to now, you seems to have found the solution to my problem)! I'm getting back soon... – Eric Ouellet Jan 15 '15 at 15:07
  • 1
    Thanks, you are totally right. Thanks a lots !!! Just FYI: I opened another question at Microsoft because Thread_UseAllCpuGroups does not work in my cases. I hope I will get a valid answer. Link: https://social.msdn.microsoft.com/Forums/vstudio/en-US/a871373d-e90d-4e26-bac1-0c45fd2f9d8e/unable-to-use-more-than-one-processor-group-for-my-threads-in-a-c-app?forum=parallelextensions – Eric Ouellet Jan 16 '15 at 17:08
  • 3
    Did you also turn on GCCpuGroup and gcServer? https://msdn.microsoft.com/en-us/library/jj665638(v=vs.110).aspx says that you need all three. – Alastair Maw May 26 '15 at 11:03
7

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>
Alastair Maw
  • 5,373
  • 1
  • 38
  • 50
  • 3
    Thanks, you are right. But I already did it. I added an update to my question because I received a lots of feedback from HP regarding this problem (added in another StackOverflow question) – Eric Ouellet May 26 '15 at 14:07
0

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).

zmechanic
  • 1,842
  • 21
  • 27
  • I know but it does not answer the reason why I only have the half. I want a documentation that says why I only have the half of it. If it is really because Environment.ProcessorCount does not take in account the second CPU then I will use that. But if I only see half of it because of a Windows Server setting, it would not be logical to multiply by the number of cpu. – Eric Ouellet Jan 15 '15 at 15:01
  • 1
    For your information, your link is to version 4 of the framework. In version 4.5 the information about the environment variable has been removed and for one good reason: that is not true. I changed the environment variable and run my app and still see only half of logical processors (all in the same environment - same cmd prompt). But thanks for trying. – Eric Ouellet Jan 15 '15 at 15:34