Parfor does not parallelize after the first time

조회 수: 3 (최근 30일)
Mehmet Selim Akay
Mehmet Selim Akay 2020년 5월 22일
댓글: Mehmet Selim Akay 2020년 5월 26일
I am using 16 workers.
My parfor loop requires 70 loops in total.
When I run the parfor it starts 16 loops.
Then as the loops finish one by one, the solver does not start new loops.
It accepts one loop at a time for the rest of load.
So the parallelization stops after the first time the load is distributed.
How can I overcome this problem? Thank you.
  댓글 수: 2
Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020년 5월 22일
Please provide your code or at least its outlines. parfor uses several techniques to figure out how to chop your matrices for parallel computationn, so it should be used carefully. Using for instead of parfor can be useful for debugging since debugging cannot be done inside a parfor loop.
Mehmet Selim Akay
Mehmet Selim Akay 2020년 5월 26일
parfor i = indexRange
x = aVector(i) ;
[A{i},B{i},C{i}] = myfunc(x,y, ...some input... );
end
Thank you for the response.
The above is what my code does.
To reiterate, when the length of "indexRange" variable is greater than the parallel workers' count, at the first time all workers are assigned a loop. But after this first distribution of work is finished, for the rest of the indexes in indexRange, it allows only one loop at a time and the CPU is underloaded.
I can only mitigate the problem with a decoration as follows:
p = 1 ; remainderIndexCount = length(aVector) ;
while remainderIndexCount > 0
indexRange = p:p+min(16,remainderIndexCount)-1 ; % 16 workers
parfor i = indexRange
x = aVector(i) ;
[A{i},B{i},C{i}] = myfunc(x,y, ...some input... );
end
remainderIndexCount = length(aVector) - indexRange(end);
p = indexRange(end) + 1 ;
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by