Specifying more cores than needed for parfor? Any speedup?

3 ビュー (過去 30 日間)
Jaya
Jaya 2021 年 11 月 8 日
コメント済み: Walter Roberson 2021 年 11 月 8 日
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.

採用された回答

Walter Roberson
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
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
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 ExchangeParallel Computing Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by