Using struct as a reduction variable in parfor loop

1 回表示 (過去 30 日間)
Tejas
Tejas 2020 年 8 月 29 日
回答済み: Walter Roberson 2020 年 8 月 29 日
I have a code which, simply put, runs in the following way
%Previous code from which the structs p, a, fa, s are initialized. The struct s contains arrays and vectors.
loop_p = p;
loop_a = a;
loop_s = s;
parfor i_iter = 1:500
a = loop_a;
p = loop_p;
s = loop_s;
for t = 1:1000
%Code which updates a, p, fa, s at each time step. This is essentially a sequential process.
end
end
The struct s is needed for post-iteration analysis. I'm stuck at using a reduction variable which will help me accumulate arrays in s and output them. I can't seem to use other structs or cells to accumulate these arrays. Would the only way be to have different variables for each field of the struct and have the arrays from the structs accumulated over iterations in these variables?
  1 件のコメント
Matt J
Matt J 2020 年 8 月 29 日
Yes, I think so.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 29 日
Basic Rules for Reduction Variables
Required (static): You cannot index or subscript a reduction variable.
The example showing something invalid is a struct field access, so the documentation explicitly rules out using a struct field as a reduction variable.

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by