What happens when a parallel worker finishes early?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Tyler Warner
le 20 Juil 2017
Commenté : Tyler Warner
le 28 Juil 2017
Hi everyone,
I have a benchmark code running where I test the time it takes from start to finish. I noticed that the workers are not synchronized. What will happen when one worker finishes early? This is a parfor loop of 20 workers on a 20-core server.
Good day!
0 commentaires
Réponse acceptée
Edric Ellis
le 21 Juil 2017
When MATLAB runs a parfor loop, it attempts to split the iterations of the loop across the workers to keep them all busy simultaneously. However, this is not always possible (especially if you have only a very small number of loop iterations, and the iterations take different amounts of time). So, towards the end of the parfor loop, some of the workers will be idle waiting for the last workers to finish.
4 commentaires
Edric Ellis
le 21 Juil 2017
Modifié(e) : Edric Ellis
le 21 Juil 2017
To expand on my answer: we don't simply divide up the parfor loop iterations across the workers - we split the iterations in differing sized groups such that there are (generally) around 3 "intervals" (groups of loop iterations) per worker. Subsequent intervals get dispatched to workers as they complete operating on their intervals - this is a relatively simple but effective means of load-balancing. We don't currently provide any way for you to tailor this scheduling, and you're right we don't try and subdivide late-finishing intervals to see if we can get other workers to operate on them.
The current scheme provides a trade-off between communication overhead and late-finishing. There are always going to be pathological cases where no scheduling system can work well. Consider the following silly example:
parpool('local', 3);
parfor idx = 1:3
if idx == 3
pause(100);
end
out(idx) = rand();
end
There is no possible scheduling that we could use for this case to keep all the workers busy at the same time.
If you want full control over the parallel scheduling, you can use parfeval.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!