Reputation: 53
In Delphi, we need to know the number of CPUs for parallelization. Until now, we have used the GetNativeSystemInfo()
function, which has worked fine, also with servers with hyperthreading.
But now, we have a server (Intel Xeon Gold 6230) with 40 physical processors and 80 logical processors with hyperthreading, and GetNativeSystemInfo()
only shows 40 CPUs.
We made a small test program that uses 3 calls:
GetNativeSystemInfo()
GetLogicalProcessorInformation()
(code from How to detect number of logical and physical processors efficiently?)
And looking into the Registry for number of CPUs:
Computer\HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor
For all of our servers, these 3 calls give the same number of CPUs:
But for the Intel Xeon, only the Registry gives us the 80 CPUs:
Does anybody know why it is not working for the Intel server, or know a way to be sure to get the max number of CPUs?
Upvotes: 4
Views: 1489
Reputation: 94
To query logical processor count greater than 64, you have to use the newer GetLogicalProcessorInformationEx
API, which the NumCPULib4Pascal library wraps in an easy-to-use manner.
Unfortunately, I can't paste the full code here because it won't fit the word limit of StackOverflow.
Sample usage below:
uses
NumCPULib;
var
lcc, pcc: Int32;
begin
// count logical cpus
lcc := TNumCPULib.GetLogicalCPUCount();
// count physical cpus
pcc := TNumCPULib.GetPhysicalCPUCount();
end;
Upvotes: 3
Reputation: 8043
In GetLogicalProcessorInformation
documentation I found this part:
On systems with more than 64 logical processors, the GetLogicalProcessorInformation function retrieves logical processor information about processors in the processor group to which the calling thread is currently assigned. Use the
GetLogicalProcessorInformationEx
function to retrieve information about processors in all processor groups on the system.
So try using GetLogicalProcessorInformationEx
.
Upvotes: 9