How to programmatically configure SetProcessAffinityMask in Delphi XE7 for Windows 2012 R2

I have a workstation whose operating system is a 64-bit Windows 2012 R2 server. I am using Delphi XE7 Update 1. The workstation has 72 cores, including hyperthreading. I want all my applications to run on all the cores that are available every time the application starts. I want to do this programmatically, namely, using the affinity set in the main task (which applies only to one group at a time, and I have two groups of 36 processors that I want to use at the same time) or boot parameters predefined from msconfig.

I understand that the question is similar or includes the following questions that are already asked in Stackoverflow

Delphi TParallel does not use all available processors

Strange TParallel.For default behavior ThreadPool

SetProcessAffinityMask - select multiple processors? .

and I also considered the offer edn.embarcadero.com/article/27267.

But my SetProcessAffinityMask question relates to a larger number of 64 cores using a 64-bit operating system and is not limited to using TParallel.

The solution I tried is the adaptation proposed by Marco van de Voort

   var 
   cpuset  : set of 0..71;
   i: integer;
   begin
   cpuset:=[];
   for i:=0 to 71 do
   cpuset:=cpuset+[i];

   SetProcessAffinityMask(ProcInfo.hProcess, dword(cpuset)); 

   end;

but it didn’t work.

I would be grateful for any suggestions.

+4
source share
1 answer

As indicated in the comments, the affinity mask is 32 bits in 32-bit code and 64 bits in 64-bit code. You are trying to install a 72-bit mask. Obviously this will not work.

, MSDN: , , 64 .

72 , . , . :

, SetThreadAffinityMask SetThreadGroupAffinity. , , , , . ; SetProcessAffinityMask.

. , , , SetThreadGroupAffinity. Delphi, . , , .

, , - . NUMA, Delphi, NUMA. NUMA, , , , NUMA node.

, , . , , , , NUMA.

+2

Source: https://habr.com/ru/post/1598530/


All Articles