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 Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by