Variable in parfor cannot be classified
Ältere Kommentare anzeigen
I've looked for answers on this forum but each situation seems to different from mine. My code sends some data to a function which outputs many variables which are defined as sets of tau coefficients (or a tau by tau matrix) on a Nx by Ny mesh.
Here is my code:
speedmaxF = 0;
system_cell = NaN(tau,Nx,Ny);
trunc_east = NaN(tau,Nx,Ny);
trunc_west = NaN(tau,Nx,Ny);
Jac_trunc_east = NaN(tau,tau,Nx,Ny);
Jac_trunc_west = NaN(tau,tau,Nx,Ny);
Jac_cell = NaN(tau,tau,Nx,Ny);
Jac_east_cell = NaN(tau,tau,Nx,Ny);
Jac_west_cell = NaN(tau,tau,Nx,Ny);
Jac_east_other = NaN(tau,tau,Nx,Ny);
Jac_west_other = NaN(tau,tau,Nx,Ny);
flux_east = NaN(tau,Nx,Ny);
flux_west = NaN(tau,Nx,Ny);
DGprev_ghosts_east = NaN(tau,Nx,Ny);
DGprev_ghosts_west = NaN(tau,Nx,Ny);
DGprev_ghosts_east(:,1:(end-1),:,:) = DGprev_ghosts(:,2:end,:,:);
DGprev_ghosts_west(:,2:end,:,:) = DGprev_ghosts(:,1:(end-1),:,:);
parfor index1 = 1:Nx
for index2 = 1:Ny
qstar = DGprev_ghosts(:,index1,index2);
qeast = DGprev_ghosts_east(:,index1,index2);
qwest = DGprev_ghosts_west(:,index1,index2);
v1center = v1centers(index1);
v2center = v2centers(index2);
cellcenter = [v1center v2center];
[trunc_east(:,index1,index2),trunc_west(:,index1,index2), ...
flux_east(:,index1,index2), flux_west(:,index1,index2), ...
Jac_east_cell(:,:,index1,index2),Jac_west_cell(:,:,index1,index2), ...
Jac_east_other(:,:,index1,index2),Jac_west_other(:,:,index1,index2), ...
Jac_trunc_east(:,:,index1,index2),Jac_trunc_west(:,:,index1,index2), ...
Jac_cell(:,:,index1,index2),system_cell(:,index1,index2),maxspeedF] ...
= predictor_precompute_eastwest(qstar,qeast,qwest,qstar,data,cellcenter);
speedmaxF(iv1ghost) = max([speedmaxF(iv1ghost) maxspeedF]);
end
end
The error message is:
Error: File: predictor_main.m Line: 146 Column: 10
The variable trunceast in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
I have tried by adding things like truncteast = trunceast after the loop, but nothing seems to work. Suggestions?
3 Kommentare
jgg
am 18 Feb. 2016
I think the issue is that because you're using two indexes, both of which can be called in any loop iteration (but aren't, in reality) Matlab is having a hard time understanding the structure of your variables. Try this and see if it works:
parfor index1 = 1:Nx
trunc_i = NaN(1,Ny);
for index2 = 1:Ny
%Stuff
[trunc_i(index2),%Stuff] = predictor_precompute_eastwest(qstar,qeast,qwest,qstar,data,cellcenter);
speedmaxF(iv1ghost) = max([speedmaxF(iv1ghost) maxspeedF]);
end
trunc_east(index1,:) = trunc_i;
end
Basically, try using a temporary variable inside the inner loop to store the values you need to assign to trunc_east then assign it only once at the end of the outer loop.
You'll have to to do the same thing with your other variables as well.
I'd had success with this in the past; hopefully it will work here.
Walter Roberson
am 18 Feb. 2016
Yes, that is an appropriate approach: write into a temporary vector in the inner loop, and assign the vector as a whole to the appropriate output space in the outer loop.
Pierson
am 22 Feb. 2016
Antworten (0)
Kategorien
Mehr zu Parallel Computing Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!