How can I set the default affinity for any process in Windows?

20,956

Solution 1

Process Lasso supports this! It comes with a free and paid version, CPU affinities is always free...

Just fill in a * in the Name match field, which will target all processes.

I think you can then add your programs to have another affinity, the order in which you enter the rules might matter. Also, you can tick More strictly enforce default affinities at the bottom.

enter image description here

Solution 2

If you go into task manager processes and right click on the process you should be able to select the affinity.

enter image description here

To disable a core you can use msconfig. I don't think you can enable it on a per-process basis.

Share:
20,956

Related videos on Youtube

Nathan Fellman
Author by

Nathan Fellman

SOreadytohelp

Updated on September 18, 2022

Comments

  • Nathan Fellman
    Nathan Fellman almost 2 years

    I want to run some benchmarks on Windows 7. These benchmarks have to do with hyper-threading on a multi-core CPU. For this, I want to ensure that only the benchmarks are running on their own logical processor. Is there any way to tell Windows to not schedule anything on there certain logical processors, unless I allow it explicitly for a process?

    Doing this manually in the task manager, one process at a time, is not an option. I want to be able to do this repeatedly (I will be running many benchmarks many times). I know how to programmatically set the affinity for the current running process.

    Is there any configuration that can allow me to set the default affinity for all processes?

    • Admin
      Admin over 12 years
      Might be better off stopping "system things" so they dont get in the way and increasing the priority and setting affinity for the benchmarks themselves, so other fuctions will only be able to use the leftover one. What do you do when the benchmark itself relies heavily ON various functions you park to the side? could effect results? EX: many benches for Disk I/O are using caches even when that is supposedly bypassing them.
    • Admin
      Admin over 12 years
      There was an old program for XP that I used for this purpose, not sure if it can be found for download now...tomshardware.com/reviews/bang-dual-processing-buck,815‌​-3.html
    • Admin
      Admin over 12 years
      I have a copy of "THG task assignment manager" if you would like to try it on W7.
  • Nathan Fellman
    Nathan Fellman over 12 years
    OK, I should've been clearer. I want to set the affinity of all processes to use only logical processors 0 and 1, and enable only the processes that I want to to use 2 and 3. Doing manually for each process is not an option.
  • Pubby
    Pubby over 12 years
    @NathanFellman Yeah, I realized that after I posted. Have you tried disabling them with msconfig->system configuration->advanced?
  • Nathan Fellman
    Nathan Fellman over 12 years
    no, I don't know how to do that :-)
  • Pubby
    Pubby over 12 years
    @NathanFellman I saw it from this: en.kioskea.net/faq/616-multicore-cpu-how-to-disable-a-core Never done it so not sure if it will work in your situation.
  • Nathan Fellman
    Nathan Fellman over 12 years
    But will this allow me to assign only certain processes to the "disabled" processors? It seems to me that this will keep all of the processes off of the processor I want to keep clear, including my benchmark.
  • Simon Sheehan
    Simon Sheehan over 12 years
    @NathanFellman I'm actually not entirely sure - perhaps you could test that?
  • Tamara Wijsman
    Tamara Wijsman over 12 years
    @NathanFellman: /NUMPROC=number sets the number of processors that Windows will run at startup. With this switch, you can force a multiprocessor system to use only the quantity of processors (number) that you specify. This switch can help you troubleshoot performance problems and defective CPUs. — See Support. This does mean that the processors can't be used anymore once you limit them.
  • surfasb
    surfasb over 12 years
    I use a similar utility for Folding@home.
  • Jamie Hanrahan
    Jamie Hanrahan over 8 years
    Note that some "system things", like interrupt handling and DPCs, will not be affected. There may also be permiision issues trying to set affinities for system threads and protected system processes.
  • Alexandros
    Alexandros almost 6 years
    I managed to do exactly what was asked using this tool. I added a * rule for logical cores 0-3 and a "javaw" rule for 4-7, then used JNA from my Java program to set affinity to cores 4 and 6. Worked like a charm, my 2 threads had the cores all to themselves. Even confirmed memory visibility taking effect using sun.misc.Unsafe store/load fences.