Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 4304  / 1 Year ago, fri, march 10, 2023, 6:09:52

On my Ubuntu 16.04, I am running a program that is relatively expensive in terms of CPU usage. It takes quite much time to finish, and other tasks (like browsing the web) get slower as a consequence. I was looking for a way to improve the computing power, if possible and at the same time to know better what is happening in my laptop.



By this, I found that, if I ask top, the program I am running shows a CPU usage of 100%, while when I open the System monitor the CPU usage is only at ~25% in the Processes tab. In addition, the Resources tab in System monitor shows 4 CPUs, whose usage changes from ~5 to ~100% for each one:



CPUs usage



The outcome of lscpu is:



@C:~$ lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 142
Model name: Intel(R) Core(TM) i5-7200U CPU @2.50GHz
Stepping: 9
CPU MHz: 3099.937
CPU max MHz: 3100,0000
CPU min MHz: 400,0000
BogoMIPS: 5423.81
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3


Is there anything I can do to improve the situation, such as dilute the work among the 4 CPUs? Usinge nice does not seem a solution to my situation.



I know this may be a general question that depends on the type of program I am running (let's say it is a Python script), but I am trying here to get general knowledge.


More From » cpu

 Answers
4

Is there anything I can do to improve the situation, such as dilute the work among the 4 CPUs? Usinge nice does not seem a solution to my situation.




In short: no. The program is single threaded.



Top can show cpu use in two ways: saturation per CPU, or share of total. If you have a four core system, top may show Irix mode:




Also for multi-processor environments, if Irix mode is Off, top will operate in Solaris mode where a task's cpu usage will be divided by the total number of CPUs. You toggle Irix/Solaris modes with the `I' interactive command.




You can toggle this by pressing I in top. As you have four CPU cores, the use is divided by four, and you will show 25%. If you turn on Irix mode, it will show 100%.



Your application is single threaded. It executes a sequential thread, on one CPU core. If you have the source code, you can change this. It's usually not a trivial task however, and depending on task it may not be possible.



Linux has a scheduler which will distribute running threads to different CPUs/cores.


[#6984] Saturday, March 11, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ntlesslving

Total Points: 123
Total Questions: 109
Total Answers: 113

Location: South Korea
Member since Fri, Sep 11, 2020
4 Years ago
;