Clear Filters
Clear Filters

Parallel Computing Hardware Setting

2 views (last 30 days)
I wrote a script that takes hours to run. I opened the Task Manager and noticed it appears to be using all the CPUs. By default does Matlab attempt to use all CPUs or is there a setting somewhere in the software to specify how much hardware it utilizes? Granted, I'd prefer it to use all available hardware, but for my own knowledge, I'd like to know how Matlab decides how much to use.
Thanks,
M Ridzon

Accepted Answer

Walter Roberson
Walter Roberson on 29 Nov 2017
By default, for "sufficiently large" computations that follow mathematical patterns that MATLAB happens to recognize, then MATLAB will call into high performance libraries telling them it is okay to use a number of threads equal to the number of physical cores (not the number of hyperthreads.) This applies even without the Parallel Computing Toolbox. This can be controlled with https://www.mathworks.com/help/matlab/ref/maxnumcompthreads.html
If you are using the Parallel Computing Toolbox, then by default each worker is given only one thread -- but for large problems the workers will still call into the high performance libraries. Because of the overhead involved in calling those libraries, this can result in some loss of performance. With sufficiently new MATLAB releases you can edit your default cluster profile to allocate more threads per parallel worker.
  2 Comments
Matthew
Matthew on 29 Nov 2017
Walter, thanks! I'm not sure what "sufficiently large" refers to or how Matlab determines that. But apparently, my current script is such since the Task Mgr shows all cores running full bore. It sounds like "sufficiently large" means you can never tell if Matlab will use parallel processing; i.e., it somehow makes a determination itself with "black magic."
And yes, I'm using a newer version (R2017a), but not the Parallel Computing Toolbox. I don't know how to set the toolbox up or use it but it appears unneeded since my script is already using all cores.
Nevertheless, thanks for the helpful feedback.
M Ridzon
Walter Roberson
Walter Roberson on 29 Nov 2017
Edited: Walter Roberson on 29 Nov 2017
"I'm not sure what "sufficiently large" refers to or how Matlab determines that."
MATLAB uses internal heuristics and does not document the exact patterns it detects or the size of problems that lead to the high performance library being called. Likely the size boundaries change every couple of releases.
Generally speaking, the operations that are really fast such as plain addition or element-by-element multiplication, have fewer opportunities for increasing performance by making extra function calls, so MATLAB would want the arrays to be large before bothering. Array sizes of roughly 10000 have been suggested as the breakpoint for those relatively simple operations. The high performance libraries know about factors such as processor cache sizes and so know how to arrange the operations in blocks for really optimal performance -- but the high performance libraries have setup costs and memory transfer costs so it is not always worth coding them.
For more complicated operations such as qr() where more work has to be done per input data point, then MATLAB calls the high performance libraries at smaller breakpoints.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!