Parfor loop with 4 workers is more than 4 times faster than the for loop, how is it possible?
3 views (last 30 days)
I have a code that contains a for loop inside a while loop.
When I change the for to parfor, the elapsed time I get is divided by "n" times, being "n" higher than 4 for some input data.
How is it possible if my pool has 4 workers? I'm using tic/toc functions to measure the time.
Edric Ellis on 28 Jun 2021
Without seeing some code that demonstrates this, we can only speculate. One possibility is that the code transformations required to make a parfor loop execute have ended up being more efficient. Is your parfor loop currently in a script? (There are different MATLAB-level optimisations available to scripts and functions - but the body of a parfor loop always has to execute in the same was as if it was placed inside a function).