Maximize CPU Usage
Asked Answered
A

4

10

How do I maximize the CPU usage for my application? I tried setting it to "Real-time" in the Task Manager, but there was no noticeable improvement - it's stuck at 50%.

I'm working in Windows XP with Visual C++ 2005.

Abandon answered 27/10, 2009 at 21:40 Comment(1)
In addition to Eclipse's reply: process/thread priority does not affect CPU load, it only affects how the available CPU is distributed among the threads waitign to be executed. If there's a single thread on idle priority, ti will get all cycles of a single core.Sankey
P
28

I'm assuming you running on a dual-core computer. Try starting another thread.

If you only have one thread of execution in your application, it can only be run on one CPU core at a time. The solution to this is to divide the work in half, and get one CPU core to run one half and the other core to run the other half. Of course you might want to generalize this to work with 4 cores or more....

Setting the priority for your application is only going to move it up the queue for which process gets first chance to use the CPU. If there is a real-time process waiting for the CPU, it will always get it before a high priority, and so on down the priority list. Even if your app is low priority, it can still max out a CPU core if it has enough work to do, and no higher-priority process is wanting to use that core.

For an introduction to multithreading, check out these questions:

Phosphoresce answered 27/10, 2009 at 21:42 Comment(1)
Thanks! Man, I feel like such a dumbass - onward ho to OpenMP!Abandon
T
9

You probably have a dual core processor and your program is probably single-threaded.

Tryout answered 27/10, 2009 at 21:43 Comment(0)
T
5

Priority will have little or nothing to do with how much CPU your process uses. This is because if there is something available to run, the OS will schedule it to be run, even if it is low priority. Priority only comes into it when there are two or more runnable threads to choose from. (Note: This is an extreme simplification.)

Number crunching programs such as Prime95 run at the lowest possible priority and spawn multiple threads to use all of as many CPUs as you have.

Theona answered 27/10, 2009 at 21:46 Comment(0)
S
0

Real time will not necessarily eat CPU cycles. Try spawning a thread or two, or three that run tight loops that count, at the most basic. If you want to (ab)use memory, you can also allocate and deallocate some arbitrary objects within your loops.

Stickler answered 27/10, 2009 at 21:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.