Possible Duplicate:
How to find the Number of CPU Cores via .NET/C#?
I have a program that controls a multi-process test environment. It works by identifying how many cores are available on a 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 machine is a 64 core AMD Opteron 6276 (4x16 cores) running Windows Server 2008 R2 HPC edition. Now here's the problem. From the command line I get the following:
>echo %NUMBER_OF_PROCESSORS%
64
Which is correct. Running the above line of code in C# gives me 32. Environments.ProcessorCount also gives me 32. I have tried a codeblock I found in Detecting the number of processors but this gives the same response (31 actually... 31 free, plus the one the code is execturing on).
Testing shows that it is really returning 32 cores. Running the program shows CPU utilisation at 50%. If I hardcode 64 into the program CPU utilisation becomes 100%. Unfortunantly I can't keep it hardcoded as this program can be run on a range of hardware. I'm wondering if it is something to do with AMDs design as CPU-Z detects 4 physical processors with 8 cores each. However it detects 16 threads. I'm wondering if C# is thinking that it's hyper threaded or something like that. Any ideas how I can get it to correctly identify all 64 cores?