MATLAB Answers

Matlab only uses half of the number of logical cores. How can I use all of them?

5 views (last 30 days)
Hello,
I am trying to use parallelization in Matlab.
feature('numCores')
it gives me
MATLAB detected: 6 physical cores.
MATLAB detected: 12 logical cores.
MATLAB was assigned: 12 logical cores by the OS.
MATLAB is using: 6 logical cores.
MATLAB is not using all logical cores because hyper-threading is enabled.
So I want to use 12 locial cores.
However if I use parpool as below
parfor i_a = 1:Na %Loop over state variable a
for i_d = 1:Nd %Loop over state variable d
for i_y = 1:Ny %Loop over state variable y
It says the number of workers is 6 and I was expecting to be 12.
How can I use 12 instead of 6?

Accepted Answer

Raymond Norris
Raymond Norris on 3 Apr 2021
Increase the cluster profile's number of workers.
c = parcluster;
c.NumWorkers = 12;
p = c.parpool(12);
You might not see an improvement. If you want to increase the worker size past the number of physical cores, increment it, 1 at a time (i.e. try parpool(7), then 8, etc.).
  3 Comments
Walter Roberson
Walter Roberson on 3 Apr 2021
HyperThreading can be great for cases where you have processes waiting for resources (such as waiting for a file page to be fetched, or for the user to move the mouse), but it can slow down the system in cases where the threads are compute bound. In most modern CPUs, they can "burst" up to a higher CPU rate if the CPU temperature is not too high, but doing so tends to heat up the CPU. When hyperthreading is not turned on, the little breaks while the CPU waits for resources give time for the CPU to cool, and the CPU can generally be run at peak speed for the time that it is actually doing computation. However with hyperthreading, the second thread takes over the CPU instead of the CPU having a break, so the heat-load tends to be higher. In order to deal with that, some CPUs lower the clock speed for both threads, to prevent the CPU from overheating.
So.. because of this effect, it can turn out to be faster to run two CPU-bound threads one after the other, which would be more likely done at burst speed for each, instead of having to turn down the CPU.
Different manufacturers and different models of CPU differ in the extend to which they throttle threads to reduce heat overload. I understand that AMD does it less -- so hyperthreads might be a better deal on AMD than on Intel. AMD base clock-speed tends to be a bit slower, but AMD core counts can be relatively high.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!