Is there an easy way to check whether a certain single-threaded application is being balanced across CPU cores by Windows?

I have already tried Process Explorer but I could not find a way to read it out, if possible in the first place.

The reason I am wanting to know this, is because I understand that not all single-threaded applications get balanced, but rather stick to 1 core instead.

  • There's really no easy way to tell, but it's hard to see how that would be useful information anyway. If it's the only thing running, you can use the task manager to look at the load on each core. – David Schwartz Jul 27 '12 at 0:18
  • 1
    Applications must be written to take advantage of multiple cores. Since the programmer has to take care of identifying which parts of the program can be split and run concurrently and then has to deal with maintaining locks on data, many developers simply don't write their apps in this way. You said not all single-threaded applications get balanced. In fact, NO single-threaded applications can be split among cores. The application must be multi-threaded. This is a great question though because I can't seem to find an answer... – Paul Ackerman Jul 27 '12 at 0:23
  • The programmer can lock an application to a particular CPU core if they want to, but there's rarely a good reason to do so. – Harry Johnston Jul 27 '12 at 2:18

"Balanced" is a relative term.

Moving a process between cores can invalidate certain optimizations (shared cache helps, but CPU registers are per core still), so if your OS is "balancing" a process by moving it around it may be causing more harm than good.
For highly optimized (often hand-crafted assembly) programs it can take longer to restore register states than to just let the process keep one CPU all to itself.

On the other hand if a CPU-Bound process doesn't use the registers heavily and doesn't so much care if they have to be reloaded, and if there is a lot of contention for the CPU, moving it around to whatever processor is available might improve performance.

What I'm getting at here is that for a single-threaded process You don't care -- Trust your operating system's scheduler to do the Right Thing (it really is smarter than you about this sort of thing).

For multithreaded processes the same logic applies, just multiple times: Do you care WHERE the threads are running as long as they're getting the CPU time they need and running quickly?
My guess is no.

To answer the question you asked: Because you really shouldn't care I don't think it's possible.

There's certainly not an easy way to get at this in Windows (the task manager and Process Explorer don't expose it anyway). You could look in to Power Shell scripting, but I don't believe there's a way to do it there either...

  • I should not care as long as it gets the CPU time it needs, but if I am planning to run multiple instances of this single-threaded application, would it not mean that only one core gets to deal with all of it? If so, I would like to assign a specific core to each of them. Would it not be a shame to have a beast of a CPU but only to be able to use one core? – Xen Jul 27 '12 at 15:09
  • @Xen A single threaded app won't limit all instances of itself to a single thread, so you don't need to worry. If you want to try to control it manually anyway, you can use Set Affinity in Task Manager. If you fire up a bunch of instances, you can set the affinity of each process (assuming multiple instances spawn multiple processes) to an individual core, if you want. That said, voretaq7's right that the OS scheduler is going to do a better job than you will of getting the application the CPU it needs. – HopelessN00b Jul 27 '12 at 21:00
  • I don't know that I'd agree that "the OS always knows better than you." I've seen huge throughput increases in single-threaded tasks before when manually assigning their affinity to a single core to keep them from jumping around. The penalty of pushing all of the thread's registers to the stack, flushing the cache to RAM (or at least L3) and then pulling all of that back into a different core can be quite significant if it's happening frequently. – reirab Nov 5 '17 at 4:54

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.