Variable in parfor cannot be classified

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

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
Walter Roberson 2016년 2월 18일
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
Pierson 2016년 2월 22일
Thanks! Very helpful. Any ideas on how to make sure that the speedup in this code is optimal?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기

질문:

2016년 2월 18일

댓글:

2016년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by