MATLAB: Parallel Computing Hardware Setting

cpuparallelparallel computingprocessor core

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

Best Answer

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.