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?
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).
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).
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)
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.