Parfor loop with 4 workers is more than 4 times faster than the for loop, how is it possible?

1 次查看(过去 30 天)
Hello,
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.
Thank you!

回答(1 个)

Edric Ellis
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).

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by