I am using Ubuntu 18.10 and running my own program using terminal, which requires many calculations, but when I open task manager, terminal CPU usage (including running program) never takes more than 26%. Here is very simple program, that behaves similarly. How can I force my program (or terminal) to use all of my CPU speed. I also tried to run multiple terminals and start program, or use threads in my code, but it appears that those 26% splits into these terminals, and run slowly. Is it terminal limit? How can I fix it and make program run faster?
#include <stdio.h>
int main(){
int a=0;
while(1){
printf("%d\n",a);
}
return 0;
}
EDIT: using just "a" instead of "a++", to avoid overflow
Okay, I managed that my task was using 100% of one of 4 CPU cores (thats why I got ~25 CPU%, it was divided by 4 cores). Using "pthread_create" function a am able to use multiple threads, and use all CPU power for that task. I learned that I/O are limiting task speed, and I should not use all of CPU power. Thank you everybody for help and knowledge, that really helped me! Some sources that also helped me to solve problem, for future readers:
pthread_create function http://man7.org/linux/man-pages/man3/pthread_create.3.html
command for CPU usage https://www.booleanworld.com/guide-linux-top-command/
compilation Undefined reference to pthread_create in Linux