Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Help: restructuring parfor

1 回表示 (過去 30 日間)
Pramit Biswas
Pramit Biswas 2018 年 4 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
totpV=5;
vars = rand(totpV,2);
for loop1=1:100
for loop2=1:totpV % Make this loop2 parallel using parfor
parameter=vars(loop2,:,loop1);
result(loop2,loop1)=feval('sum',parameter); % sample function
if min(result(loop2,:))<=result(loop2,loop1)
best=result(loop2,loop1);
end
vars(loop2,:,(loop1+1))= vars(loop2,:,loop1) + rand(1,2).*best;
end
end
I want to process loop2 parallelly, however, not getting how. From This page, probably this is due to Sliced Variables. Any idea to restructure?
Errors: The PARFOR loop cannot run due to the way variable 'vars', 'result' is used.
  1 件のコメント
Adam
Adam 2018 年 4 月 6 日
What are the warnings you get when you try?

回答 (1 件)

Bhavanithya Thiraviaraja
Bhavanithya Thiraviaraja 2018 年 4 月 17 日
編集済み: Bhavanithya Thiraviaraja 2018 年 4 月 17 日

There seems to be a dependency between the iterations in the line

min(result(loop2,:))<=result(loop2,loop1)

In parfor, the iterations are performed on independent MATLAB workers and hence it requires 'No Dependency'. In this case, the min(result(loop2,:)) seems to use the previously calculated values also, hence making it dependent.

Refer https://de.mathworks.com/help/distcomp/ensure-that-parfor-loop-iterations-are-independent.html for examples!

The dependency has to be broken without affecting the algorithm to use parfor.

この質問は閉じられています。

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by