有没有一种方法,以可靠地检测CPU内核总数?
我需要一个可靠的方法来检测核有多少CPU的计算机上。我创建一个数字激烈模拟C#应用程序,并希望创建运行的线程的内核的最大数量。我试图像Environment.ProcessorCount在互联网附近的许多方法建议,使用WMI,这code:的http://blogs.adamsoftware.net/Engine/DeterminingthenumberofphysicalCPUsonWindows.aspx没有人似乎认为AMD X2拥有两个核心。有任何想法吗?
I need a reliable way to detect how many CPU cores are on a computer. I am creating a numerically intense simulation C# application and want to create the maximum number of running threads as cores. I have tried many of the methods suggested around the internet like Environment.ProcessorCount, using WMI, this code: http://blogs.adamsoftware.net/Engine/DeterminingthenumberofphysicalCPUsonWindows.aspx None of them seem to think a AMD X2 has two cores. Any ideas?
编辑:看来Environment.ProcessorCount正在返回正确的号码。这是一个英特尔CPU的超线程即返回错误的号码。一个劲儿地核心与超线程的回归2,当它应该只有1。
it appears that Environment.ProcessorCount is returning the correct number. It's on a intel CPU with hyperthreading that is returning the wrong number. A signle core with hyperthreading is returning 2, when it should only be 1.
请参阅http://stackoverflow.com/questions/188503/detecting-the-number-of-processors
另外,使用 GetLogicalProcessorInformation()
的Win32 API:的 http://msdn.microsoft.com/en-us/library/ms683194(VS.85)的.aspx
Alternatively, use the GetLogicalProcessorInformation()
Win32 API: http://msdn.microsoft.com/en-us/library/ms683194(VS.85).aspx