Specifying more cores than needed for parfor? Any speedup?

3 views (last 30 days)
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.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Nov 2021
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 Comments
Matt J
Matt J on 8 Nov 2021
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 on 8 Nov 2021
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)

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel Computing Fundamentals 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!