Is there any way to force a program to run on cpu1 rather than cpu0 given that I know that there are at least two cores?

I'm compiling C++ with code::blocks on Windows 7 x64

  • 1
    I'd lean toward saying this is a SO question. – rob Jul 14 '11 at 0:08

I know that you can pull up task manager and look for your application that is running. Right click on the application in the task manager and select Affinity.

enter image description here

Then you can select the processors you wish to use.

enter image description here

  • 1
    Note that I don't think this is a GUARANTEE that they'll only run on the selected cores, only quite literally an affinity. If there are threads that Windows feels it A: Can move and B: Should move, it C: Will move them. This also doesn't keep other things from running on those cores (which is the subject of a long standing question I have open :/) – Shinrai Jul 14 '11 at 14:22

Yes there is in the Windows API: SetProcessAffinityMask(). You can also set a processes affinity using task manager as shown here.

There aren't very many valid reasons why you would want to do that. The OS generally does a good job of scheduling programs on the correct CPU.

  • Do you know if there is also a way to run a thread on a particular core? Because GSC Game World claimed in one update to S.T.A.L.K.E.R. that they moved the calculation of detailed objects to the second processor core and I can't imagine that they used a full-fletched process for that, a simple thread would make more sense. (stalker.filefront.com/file/…) – Felix Dombek Jul 14 '11 at 6:08
  • 2
    There is SetThreadAffinityMask(), but most likely S.T.A.L.K.E.R didn't use that. They just moved the calculation from their main game logic thread and put it in it's own dedicated thread and letting the OS handle scheduling the thread on a different CPU. – shf301 Jul 14 '11 at 14:16

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.