Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Is this parfor fixable?
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
aid = 100;
% matrices to fill
iass = NaN(mma,aid,2,3,aid+run);
% dummy to make parfor work
s = aid+1;
% part A: recalculating paths for those already alive
parfor (i = 2:aid,6)
wag = wages(1:aid+1-i);
r = rint(1:aid+1-i);
gamma = CoSurv(i,:,1);
iass(:,:,:,:,s-i) = recalc_paths(aid, pars, i-1);
end
With error "unable classify variable iass". It /should/ be properly sliced - each loop sets a "row" of iass, completely independently of all the other loops (but which does depend on the loop number i). Is there a way to fix this that I'm missing? I introduced the dummy "s" because it gave me a different error when I inserted aid+1 directly into the index, but clearly that wasn't the silver bullet I thought it would be.
0 Kommentare
Antworten (1)
Gaurav Garg
am 12 Okt. 2020
Hi Jacob,
Apparently, you cannot subtract the loop index (within parfor loop) from any other scalar/vector quantity.
As a workaround in your case, you can assign the final values returned by the function "recalc_paths" in a temporary variable indexed by i and then write another for loop (parfor won't work here, again due to the same reason/error of classify variable) to assign the values to iass(:,:,:,:,s-i).
Pseudo-Code:
% Declaring temp as a matrix of suitbale size and type
parfor (i = 2:aid,6)
% Finding gamma and other values
temp(i) = recalc_paths(aid, pars, i-1);
end
for (i = 2:aid,6)
iass(:,:,:,:,s-i) = temp(i);
end
2 Kommentare
Walter Roberson
am 12 Okt. 2020
According to https://www.mathworks.com/help/coder/ug/classification-of-variables-in-parfor-loops.html#btfitu2-19
Form of Indexing. Within the list of indices for a sliced variable, one index is of the form i, i+k, i-k, k+i, or k-i.
- i is the loop variable.
- k is a constant or a simple (nonindexed) variable.
- Every other index is a constant, a simple variable, colon, or end.
In the user's case, s is a "simple (nonindexed) variable", and k-i form is being used.
The user is using R2019b, but the rules for subtraction where the same then; https://www.mathworks.com/help/releases/R2019b/coder/ug/classification-of-variables-in-parfor-loops.html
Therefor, the operation is documented as being permitted.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!