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