Parfor loop introduces strange R%1 variable when using 2 reduction variables
古いコメントを表示
Problem:
When I run my code that has two reduction variables, a strange R%1 variable gets created.
If you were to run the following example code, resembling the syntax of my real code:
clear all;
N = 100;
A = 0;
B = 0;
parfor n = 1:N
A = A + 3;
B = B + 4;
end
Matlab creates a strange R%1 variable in the workspace:

If one were to click on the variable, Matlab throws an error that the variable is an invalid expression.
When you comment out either A or B in the parfor loop, the variable is not created:
clear all;
N = 100;
A = 0;
B = 0;
parfor n = 1:N
A = A + 3;
%B = B + 4;
end

Two questions:
- What am I doing wrong/missing here?
- Is the result affected? i.e. is R%1 a warning that my result is not what I would expect it to be?
A big thank you to anyone who can help me out!
採用された回答
その他の回答 (1 件)
Yair Altman
2019 年 1 月 4 日
編集済み: Yair Altman
2019 年 1 月 4 日
1 投票
I was able to reproduce your problem on my R2018a and R2018b Windows10 installation, but not in 19a.
Apparently this bug (it is definitely one) was fixed for the upcoming 19a release. This being said, I don't believe that the results are affected - it looks like an interim value that was simply left un-cleared by the parallelization engine.
If this bothers you in 18a and you are unable to use 19a, then contact MathWorks and ask them if they could give you a workaround or patch that will fix the problem in 18a.
カテゴリ
ヘルプ センター および File Exchange で Parallel Computing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!