In C #, GetEnvironmentVariable ("NUMBER_OF_PROCESSORS") returns an invalid number

Possible duplicate:
How to find the number of processor cores through .NET / C #?

I have a program that manages a multi-process test environment. It works by determining the number of cores in the system and creating as many jobs as there are cores. The code that does this is as follows:

string NumberOfProcesses = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"); 

The device is a 64-core AMD Opteron 6276 (4x16) processor with the HPC version for Windows Server 2008 R2. Now here is the problem. From the command line, I get the following:

 >echo %NUMBER_OF_PROCESSORS% 64 

It is right. Executing the above line of code in C # gives me 32. Environments.ProcessorCount also gives me 32. I tried the code that I found in CPU Number Detection , but it gives the same answer (31 actually ... 31 is free, plus one which the code is called on).

Testing shows that it really returns 32 cores. Running the program shows the processor load at 50%. If I load 64-bit code into the program, the processor load becomes 100%. Unfortunately, I cannot keep it hard-coded, as this program can run on a number of hardware. I am wondering how this relates to AMD design, as the CPU-Z detects 4 physical processors with 8 cores each. However, it detects 16 threads. I am wondering if C # thinks this is hyperthreading or something like that. Any ideas how I can get it to correctly identify all 64 cores?

+2
source share

All Articles