How to prevent parfor from slowing down towards later iterations?
Show older comments
Hi there,
I'm running lots of simulation on an HPC in a parfor loop. The number of iterations is around 150000. I propably want to do more than that at a later time.
My scripts and functions print out a progress update into a text log after each iteration and I notice that the main parfor loop I'm utilizing slows down dramatically towards the end. The cpu time elapsed per iteration does not change apart from slight variations, leading me to believe that towards the end, fewer workers are utilized.
Does matlab assign all of the work and iterations to each worker once at the start of the parfor loop and then keep workers idle which are finished quicker than the others? It seems like a couple unfortunate workers are stuck finishing their allocated iterations, while the rest idles?
Is there a way to change this?
Accepted Answer
More Answers (1)
Is there a way to change this?
I suspect not. Firstly, if you have reduction variables, the workers that aren't iterating aren't really "idle". They need to store their accumulated portion of the reduction variables until they can be combined with the portion from other workers.
Also, it can be counter-productive for one worker to broadcast part of its tasks to an idle worker midstream. In particular, any temporary variables residing on the non-idle worker would have to be cloned and broadcast. This will have overhead, especially if the temporary variables are large. At the very least, a complex decision would need to be made as to when these extra broadcasting steps are worth it.
Categories
Find more on Parallel for-Loops (parfor) 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!