Parfor loop introduces strange R%1 variable when using 2 reduction variables
Mostra commenti meno recenti
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!
Risposta accettata
Più risposte (1)
Yair Altman
il 4 Gen 2019
Modificato: Yair Altman
il 4 Gen 2019
1 voto
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.
1 Commento
Wouter Grimme
il 4 Gen 2019
Categorie
Scopri di più su Parallel Computing Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!