Parfor does not parallelize after the first time

3 Ansichten (letzte 30 Tage)
Mehmet Selim Akay
Mehmet Selim Akay am 22 Mai 2020
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 Kommentare
Abdolkarim Mohammadi
Abdolkarim Mohammadi am 22 Mai 2020
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 am 26 Mai 2020
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

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by