Specifying more cores than needed for parfor? Any speedup?
조회 수: 3 (최근 30일)
이전 댓글 표시
A trivial question: Does specifying to use more cores than the no. of parfor iterations in the code make the execution time any faster? Like how is the iterations work divided then?
We can have no. of parfor iterations> no. of cores but I want to know the other way around. Since I am using a remote computing node and I am supposed to define the number of cores I want. I specify the no. of cores equal to be no.of parfor iterations I have. But I can specify more cores and so I got this question.
댓글 수: 0
채택된 답변
Walter Roberson
2021년 11월 8일
If you have more workers than iterations, then you waste time creating the workers, which takes time and memory.
Sure, if you have already used a parallel region that used all the workers in the pool, or will do so later, it is typically not worth destroying the pool and building a new one.
An exception might be if you are paying for processor or memory use, in which case it might be worth-while to shut down a pool that has more workers than you need and then start up another pool.
댓글 수: 2
Matt J
2021년 11월 8일
I wonder, though, if performance would also even be diminished? It is conceivable that PARFOR might reserve resources for cores that never end up getting used.
Walter Roberson
2021년 11월 8일
Inactive workers are sleeping; I believe they are waiting for TCP data.
It is possible that MATLAB uses shared memory segments and sends a signal to notify of updates (that could explain some of the oddities about dealing with clusters that have multiple nodes.) But Windows has messages instead of signals... though I guess MATLAB might use MPI... I would have to see if I can remember more of the hints that have appeared...
Anyhow, it is pretty clear that the inactive workers are not "busy-waiting". So the host operating system is not going to schedule them until they are needed. They would use up process slots, which would not typically be a problem (my Mac has over 450 processes at the moment!). More important is that they would use up memory. If memory was short, the operating system might need to spend resources compressing the RAM (MacOS) or swapping to disk (Mac, Linux, Windows)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!