how can run with full cpu and all cores?

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
You can do this by making your program multi-threaded, such that each core can take a thread each.
There is no guarantee that multiple threads will run in different cores, use thread affinity for this.
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
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).
i am working on cfd and each run may takes 4 or 5 hours .
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.
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
Does every node depend on the calculations of the nodes that came before, or can you calculate them independently?
it depends. it is guess sidel iterative method to solve linear systems.
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.
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.
No one sees a problem with this? why the heck would you want to take up your CPU?
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.