Why does the Activity Monitor on Mac not show a full CPU usage when running MATLAB jobs with the built-in multithreading feature?

7 views (last 30 days)

On my 8-core Mac machine, when I run the "eigs" function on a large sparse matrix, the Activity Monitor shows MATLAB's CPU usage at about 750%

I have learned that Activity Monitor on Mac doesn't cap CPU usage percentage at 100%; rather, it allocates 100% per core. Given this, with an 8-core system, which effectively has 16 logical cores due to multithreading, the total CPU capacity can reach up to 1600%.
The "eigs" function does indeed leverage the MATLAB built-in multithreading feature, as detailed here:
https://www.mathworks.com/discovery/matlab-multicore.html .

According to the Activity Monitor, the CPU usage for running the "eigs" function, at 750%, utilizes less than half of the total available CPU capacity. Why is MATLAB not leveraging more CPU power to improve performance?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Apr 2024
If the machine has 8 physical cores and the maximum CPU usage reported is 1600%, this indicates that the measuring tool (such as Activity Monitor) calculates usage based on the number of logical cores. Since MATLAB determines the number of computational threads using the physical cores, Activity Monitor typically reports a maximum of 800% for MATLAB's usage.
However, this does not imply that MATLAB is utilizing only half of the machine's capacity. In reality, MATLAB is making full use of the physical machine, engaging all 8 physical cores completely. To confirm this, feel free to try the following experiment:
numCores = 8; % Set numCores to the number of physical cores on your device
maxNumCompThreads(numCores); % Checks default: set to use all physical cores
A = rand(3000);
tic; for i = 1:3000, x = A .* A; end; toc; % Observe MATLAB appearing to use only half the machine's capacity
maxNumCompThreads(16); % Set to use all logical cores, 8 x 2 = 16
tic; for i = 1:3000, x = A .* A; end; toc; % Expect to see much higher CPU usage, though not necessarily faster
If the Activity Monitor shows a significant increase in CPU usage after doubling the number of MATLAB threads, yet the elapsed times for both operations are roughly the same, it confirms that MATLAB is indeed utilizing all physical cores, despite the Activity Monitor not reflecting the maximum reported usage.

More Answers (0)

Categories

Find more on Install Products in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!