Parallel Computing Hardware Setting
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2017-11-29
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 个评论
Walter Roberson
2017-11-29
编辑:Walter Roberson
2017-11-29
"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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!