views:

326

answers:

4

Hi,

As I've created the application that is hard on calculations -> lots of work to do, not very complex calculations -> it takes too long to work it out and the process is only at 45% of the CPU. Can I maximize it somehow?: to go to 90%?

+6  A: 

If you have a dual core machine (which I'm guessing you do), the most you could hope to get in a single thread would be 50% CPU usage.

To get 90% CPU usage, you will most likely need to thread your calculations. This may be very simple, or very difficult, depending on the nature of the algorithm you want to thread.

If you can break up your working set into multiple groups, I would recommend considering using the ThreadPool, or potentially even the Task Parallel Library, depending on your timing for release.

Reed Copsey
+2  A: 

More than likely you have a dual core CPU, and if your app is single threaded, the maximum CPU it will use is 50% (all of one core). In order to get better use, you need to utilize multiple threads, but that also means figuring out some way to break your calculations into pieces so that they can be worked on by more than one core.

Mystere Man
+1  A: 

If you just have a simple loop doing the calculations, then most likely your computer has two cores/processors. A single threaded application will at best use 50% of the CPU.

You need multiple threads to use the whole CPU on a multi-core machine.

ScottS
simple loop != single thread
Samuel
+2  A: 

Check this:

  1. Do you read from disk while calculating? If so, try to read data in memory before calculations.
  2. Do you write results to disk or console while calculating? If so, try to postpone writing until calculation is over and then do writing.
  3. If you have multicore processor, try to create multithreaded algorithm if possible.
zendar