Reputation: 3233
When I run a single-threaded program that i have written on my quad core Intel i can see in the Windows Task Manager that actually all four cores of my CPU are more or less active. One core is more active than the other three, but there is also activity on those. There's no other program (besided the OS kernel of course) running that would be plausible for that activitiy. And when I close my program all activity an all cores drops down to nearly zero. All is left is a little "noise" on the cores, so I'm pretty sure all the visible activity comes directly or indirectly (like invoking system routines) from my program.
Is it possible that the OS or the cores themselves try to balance some code or execution on all four cores, even it's not a multithreaded program? Do you have any links that documents this technique?
Some infos to the program: It's a console app written in Qt, the Task Manager states that only one thread is running. Maybe Qt uses threads, but I don't use signals or slots, nor any GUI.
Link to Task Manager screenshot: http://img97.imageshack.us/img97/6403/taskmanager.png
This question is language agnostic and not tied to Qt/C++, i just want to know if Windows or Intel do to balance also single-threaded code on all cores. If they do, how does this technique work?
All I can think of is, that kernel routines like reading from disk etc. is scheduled on all cores, but this won't improve performance significantly since the code still has to run synchronous to the kernel api calls.
EDIT
Do you know any tools to do a better analysis of single and/or multi-threaded programs than the poor Windows Task Manager?
Upvotes: 7
Views: 4985
Reputation: 1069
THis a topic of research at the moment. Parallel compilers are supposed to find opportunities of concurrency in your program and execute them in parallel. But it is a very tough task.
There are languages like OpenMP which are designed to give this hint to the compiler. Currently most implementation of OpenMP use a threading library in the background. But in future they will not.
You might perhaps need very different hardware for that.
Short answer is, not today but most likely via OpenMP in future. But then you also need to define what you mean by a "thread",
Upvotes: 1
Reputation: 1
I use Windows 7 x64 Home Premium and an Intel i7 920 CPU and single threaded programs jump from core to core so I don't see how it is an improvement over XP.
7 does recognize HT (Hyper Threading) and doesn't schedule multiple tasks to the one CPU Core, that is probably the only benefit 7 has over XP. I did not have a multi core processor with XP for long so not sure if XP took into account HT.
Upvotes: 0
Reputation: 1
A better Windows Task Manager is sysinternals process explorer.
In Windows Task Manager (or in sysinternals process explorer), right-click on your process name, and set (choice) the affinity core, you should see now only one core active...
Which Windows do you use ? XP ? Seven ?
If you use XP, try Seven, cores are better managed.
Upvotes: 0
Reputation: 76611
A single threaded process will only ever run on a single core at any given moment in time.
But it's possible for the OS to migrate a thread from one core to another. While the OS will try to keep a thread on the same core, if the last core the thread ran on is busy and another core is free, the OS can migrate the thread.
Upvotes: 11
Reputation: 662
The tool that you want to do deeper analysis than Task Manager can is called perfmon (perfmon.exe) - it's a UI for capturing and graphing the performance counters which instrument Windows. You can use it to monitor all sorts of information on both a system and per-process level; learn to love it - it's one of a developer's best friends.
http://technet.microsoft.com/en-us/library/bb490957.aspx
Upvotes: 2
Reputation: 2398
Despite what you may perceive, there is a lot more goign on in the CPU than just your application. The OS, and all its processes and threads are also running. what you're seeing is your process being scheduled on different cores at different times. Your application is not being parallelized - its just one of many tasks that are currently executing. Be assured your app is running sequentially.
Upvotes: 0
Reputation:
What version of Windows, XP and before have a terrible thread scheduler that actually will jump a single threaded task from core to core. And under Windows (like every other OS) there are dozens if not hundreds of non-user programs running at one time regardless of what you think YOU are running that can account for all that activity.
Upvotes: 1
Reputation: 46985
Yes unless you utilize "processor affinity" threads (one or many) will be scheduled on whatever processor the kernel thread management code assigns. There is no guarantee this will be the same processor from one instruction to the next
Upvotes: 0