MATLAB: What happens when a parallel worker finishes early

parallel computingParallel Computing Toolboxparfor

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!

Best Answer

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.