Understanding parfor restrictions with indexing

28 ビュー (過去 30 日間)
Henry Shackleton
Henry Shackleton 2019 年 6 月 17 日
編集済み: Edric Ellis 2019 年 6 月 18 日
I was attempting to parallelize a for loop in MATLAB with parfor, and came across a strange restriction with regards to indexing. Specifically, the fact that you seemingly cannot use more than one different index into a variable. For example, something like
parfor ii=1:10
A(ii, 1) = 1;
A(ii, 2) = 2;
end
does not work, whereas the code
parfor ii=1:10
A(ii, :) = [1,2]
end
does. Why is this the case? I can make my code accomodate this restriction, but I can't understand why it's necessary. The two different methods seem equivalent to me with respect to being able to cause unintended side effects in parfor.

採用された回答

Edric Ellis
Edric Ellis 2019 年 6 月 18 日
編集済み: Edric Ellis 2019 年 6 月 18 日
The indexing restrictions in parfor range from those which are required to make the loop iterations provably order-independent (well... modulo non-standard implementations of subsref or subsasgn), to those which are limitations of the implementation. In this case, you have two indexing expressions either of which on its own would constitute a valid "slicing" operation, but the current implementation cannot support that.
Also note that the following is allowed:
parfor ii=1:10
for jj = 1:2
A(ii, jj) = jj;
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by