Is it possible that a single-threaded program is executed simultaneously on more than one CPU core?

孤者浪人 提交于 2019-12-03 14:20:05

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.

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

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.

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",

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

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!