Parfor loop with 4 workers is more than 4 times faster than the for loop, how is it possible?
조회 수: 1 (최근 30일)
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 2021년 6월 28일
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).