4

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:

  1. GetNativeSystemInfo()

  2. GetLogicalProcessorInformation() (code from How to detect number of logical and physical processors efficiently?)

  3. 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:

image

But for the Intel Xeon, only the Registry gives us the 80 CPUs:

image

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?

Community
  • 1
  • 1
Toke
  • 53
  • 4
  • 1
    I personally use `GetLogicalProcessorInformationEx`, probably for the reason Fabrizio gives. Although it would not be a total surprise if hyperthreading was disabled in the BIOS of your machine, considering that hyperthreading is useless. You might also need to get to grips with processor groups, `SetThreadGroupAffinity`, and the fact that, as far as I am aware, there is no Delphi memory manager that respects NUMA nodes. – David Heffernan Aug 07 '19 at 09:22
  • There is a whole chapter in MSDN's documentation on this topic : [Multiple Processors](https://learn.microsoft.com/en-us/windows/win32/procthread/multiple-processors), and in particular [Supporting Systems That Have More Than 64 Processors](http://download.microsoft.com/download/a/d/f/adf1347d-08dc-41a4-9084-623b1194d4b2/MoreThan64proc.docx) – Remy Lebeau Aug 07 '19 at 09:43
  • Thanks for the help. It is not our servers and hyperthreading is turned on. We dont use the CPU's in Workbench but spawn a Fortran code that will use the number of CPU we tell it to do. We will look into GetLogicalProcessorInformationEx – Toke Aug 07 '19 at 12:50

2 Answers2

9

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.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104
2

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Xor-el
  • 84
  • 1
  • 1
  • 3
  • 4
    I'm afraid that sometimes this happens. And people often don't want to criticise because it can lead to futile discussions. And sometimes backslashes of revenge voting. And sometimes people just don't have the time. From my perspective I'd say that this answer doesn't address why the behaviour in the question occurs. It doesn't speak to why this library won't also suffer from the same problem. And it also is close to being a link only answer to off site code. Generally it is preferable not to have link only answers. – David Heffernan Aug 07 '19 at 13:11
  • @David Heffernan, thanks for your explanation and you are right that my answer doesn't really answer the question why but just tends to provide a solution. Will update the answer with the proper information. – Xor-el Aug 07 '19 at 13:19
  • 1
    I recommend you convert this to a comment. – David Heffernan Aug 07 '19 at 17:17
  • THnaks for all the help. Using the NumCPULib4Pascal library worked. – Toke Sep 24 '19 at 12:55