8

I have an executable foo.exe that I need to run concurrently 6 times on a multiprocessor setup where the first 3 instances will be assigned to cores in Group 0 and the next 3 instances will be assigned to the cores in Group 1.

I have 6 shortcuts for the foo.exe program on my desktop. Each shortcut gives the foo.exe program a different set of parameters to run with.

I simply click on the shortcuts to run the 6 instances of the foo.exe programs. They all start up, however I then have to go into the task manager and make sure 3 are assigned to CPU's in group 0 and 3 are assigned to the CPU's group 1, by setting their group affinity.

Is there a way I can modify the shortcuts I have on my desktop to make sure 3 of the foo.exe programs use Group 0 and 3 of them use Group 1?

9

You can use the /affinity flag using the start command to specify the cores a process should use.

Usage

start /affinity n foo.exe -arguments

So, your shortcut would look like:

c:\windows\system32\cmd.exe /C start /affinity n foo.exe -arguments where n is CPU core number +1.

So to run on Core 0 it'd be:

c:\windows\system32\cmd.exe /C start /affinity 1 foo.exe -arguments.

Source

Specifying multiple cores

Assume a CPU has 4 cores. To specify the cores to use:

  1. Visualize the cores as an array with the length of the array equal to the number of cores. The cores will be arranged in descending order from right to left:

    [CPU3, CPU2, CPU1, CPU0]

  2. Now, replace cores you would like your process to use with 1 and those you won't with 0. Assuming I want my process to use core 3 & 1, my array would like this:

    [0,1,0,1]

  3. "Pop" the elements of the array to a string. Now it would be represented as 0101.

  4. Assume the string is in binary and convert it to hexadecimal. Now it would be 0x5

  5. Now use the same command start /affinity n foo.exe -arguments but now n will be 0x5, giving start /affinity 0x5 foo.exe -arguments

Source

Notes:
  • The source explains the visualization as a binary string, not an array( check it out). I find this a bit confusing so I explained using an array.
  • The source does not specify that you must prefix 0x to show it's hexadecimal in the command. Reading start /? specifies it is to be hex.
2
  • 1
    Thank you! This is very helpful. With CPU's that have a large number of cores, they are further divided into Groups. For example a Xeon E5 2699-v3 has 36 cores and they are divided into 2 groups. Group 0 has 18 cores, and Group 1 has 18 cores. Since foo.exe is multithreaded is there any way I can tell it to use all the cores in Group 0? I think there are two command line parameters, one sets the Group that foo.exe will run in (Group 0 or Group 1) and the second parameter (affinity?) tells foo.exe which cores to use in that Group.
    – Zareh
    Dec 16 '16 at 17:38
  • I found to launch a process on cores 13-16 I had to make the binary calculation then convert it to hex (e.g., 61440 becomes 0xF000) otherwise it launched on three incorrect cores. Jul 14 '20 at 14:16
0

I don't know if processor group assignment is possible on the command line, but you can set the required NUMA node number using start /node <node_number> /affinity <affinity_value>. Windows promise you that that the entire node will be contained in a single processor group. If the Node processor count is higher than 64 processor than windows will divide it into multiple virtual nodes. So if you using node you basically set the process to run on the node's processor group...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.