how can run with full cpu and all cores?

Dec 8, 2011 at 1:16pm
hi everybody. i have a c++ code and when i run it, it consumes only 25% of cpu( i have seen from task manager) i think it uses only one core. how can i run my program to use for example 90% of cpu? and what should i do to use all cores?
Last edited on Dec 8, 2011 at 1:16pm
Dec 8, 2011 at 1:24pm
You can do this by making your program multi-threaded, such that each core can take a thread each.
Dec 8, 2011 at 3:54pm
There is no guarantee that multiple threads will run in different cores, use thread affinity for this.
Dec 8, 2011 at 4:33pm
Yes, that's because it's running on one core only. You have to make your code somehow parallel.

There are basically 2 solutions, which you can google easily: one is multithreading (openMP) and the other is literally to start several versions of the program simultaneously (MPI).

Last edited on Dec 8, 2011 at 4:34pm
Dec 8, 2011 at 5:17pm
The more important question is WHY do you want to use all your CPU cycles? If your program is running properly, forcing it to use all CPU cores at 90% is like driving around in first gear with your engine RPMs red-lined. A well designed, efficient program uses the smallest number of cycles possible. There's no advantage to taxing your processors unless you actually need those cycles (unless you want to warm your feet on your PC of course).
Dec 8, 2011 at 6:57pm
i am working on cfd and each run may takes 4 or 5 hours .
Dec 8, 2011 at 7:20pm
Start by profiling your code and seeing what's eating the most processor. If it's something inelegant and inefficient, you can make some easy savings.
Dec 8, 2011 at 8:01pm
its not inefficient it has a lot of computations . it is 1000000 node and it should do some calculations in each node.( for example in some part of it (part 1) i have 1000000 unknown and i should compute these unknowns with guess sidel method that is an iterative procedure and it makes much time)
Last edited on Dec 8, 2011 at 8:02pm
Dec 8, 2011 at 8:06pm
Does every node depend on the calculations of the nodes that came before, or can you calculate them independently?
Dec 8, 2011 at 8:13pm
it depends. it is guess sidel iterative method to solve linear systems.
Dec 8, 2011 at 8:20pm
If you want to use four cores at once, you need to use threads. To make threads meaningful, your calculations have to be able to be run in parallel.

The Gauss-Seidel method is iterative and relies on each previous step - to the best of my knowledge, it cannot be split into parallel, so is not able to take advantage of multiple cores.
Dec 8, 2011 at 8:29pm
thanks alot for your help . i have noticed that it cant be split into parallel. of course in Gauss Sidel method each step results will be used in next step and as you mentioned it can not be split.
Dec 8, 2011 at 9:46pm
No one sees a problem with this? why the heck would you want to take up your CPU?
Dec 8, 2011 at 9:52pm
why the heck would you want to take up your CPU?


Yes, why get your answer in one hour when you could wait four hours instead?
Topic archived. No new replies allowed.