Help! "Parfor" error: Subscripted assignment dimension mismatch

Hi. I'm converting some sequential codes into parallel codes. The former works well. But I came across the following errors when running the parallel codes. Can anyone help me? Thanks.
??? Error using ==> parallel_function>make_general_channel/channel_general at 843 Subscripted assignment dimension mismatch.
Error in ==> parallel_function>distributed_execution at 752 [tags, out] = P.getCompleteIntervals(chunkSize);
Error in ==> parallel_function at 564 R = distributed_execution(...
Error in ==> SensitivityForNaturalBreachFreqParfor3 at 8 SANaturalBreachFreq = zeros(4,14);
??? Operation terminated by user during ==> NormalFlow
In ==> NaturalBreachFreq at 275 [h_begin, u_begin] = NormalFlow(Q_begin,B_prtC,s_prtC,n_prtC);
In ==> parallel_function>make_general_channel/channel_general at 843 O = F(C{:});
In ==> remoteParallelFunction at 28 out = distcompMakeByteBufferHandle(distcompserialize(feval(channel, channelArgs{:})));
****************The parallel codes:
SANaturalBreachFreq = zeros(4,14); % The outputs
parfor i=1:4 % Test four iterations
V = zeros(1,14);
V(i,1:3) = SA3Parameters(i,1:3); % All inputs loaded into the workspace
[Z_prtC,Z_levee] = ChnlElevations(H_prtC,V(i,1),rDep_chnl,rDep_bsn);
E_weak = 0.2*V(i,2)^(-0.5)*1e-6;
Lweak = 0.05*L_prtC/V(i,3);
[BreachYearNo,BigBreachYearNo,BreachNo,BigBreachNo,AvulsionNo,AllBreachNo,MajorBreachW,MajorBreachQout_pct,...
Avulsion,AllBreachYearNo]...
= NaturalBreachFreq(Qd,Qsd,Qpct_overtop,Qpct_bifur,Qpct_avlsn,yBifur,Big_pct,H_prtC,Z_prtC,Z_levee,...
B_prtC,s_prtC,n_prtC,tauCr,V(i,2),nDcr,V(i,3),Lweak,E,E_weak,D_breach0,B_breach0,dL,n_star,...
n_breach,dL_outfl,p_wash,d50,ws_m,rho_s,rho_m,p,dt);
V(i,4) = AvulsionNo;
if ~isempty(Avulsion)
V(i,5) = Avulsion(1);
V(i,6) = Z_levee(Avulsion(3))/Hbar;
end
V(i,7) = AllBreachYearNo;
V(i,8) = BreachYearNo;
V(i,9) = BigBreachYearNo;
V(i,10) = AllBreachNo;
V(i,11) = BreachNo;
V(i,12) = BigBreachNo;
V(i,13) = MajorBreachW;
V(i,14) = MajorBreachQout_pct;
SANaturalBreachFreq(i,:) = V;
end

 採用された回答

Edric Ellis
Edric Ellis 2012 年 10 月 24 日

1 投票

In the body of your loop, you create V as 1-by-14, but you assign into it using "V(i,1)" etc. Finally, you assign into "SANaturalBreachFreq(i,:) = V;" - this will be incorrect because "V" is now not the correct size. Surely you should be doing something more like
parfor i = 1:4
V = zeros(1,4);
V(1) = ...;
...
V(14) = ...;
SANaturalBreachFreq(i,:) = V;
end

1 件のコメント

Yunzhen Chen
Yunzhen Chen 2012 年 10 月 25 日
Edric, you're right! I corrected the codes and it worked. Thank you very much.

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2012 年 10 月 23 日

0 投票

Please use the debugger to find the source of the problems:
dbstop if error
Now Matlab stops when the error occurres - at least I hope this concerns your parallel parts of the code also.
Then you can inspect the dimensions of the local variables to find out, what's going on. At least you can post the corresponding line only, instead of a bunch of correctly working lines.
Remark:
0.2*V(i,2)^(-0.5)*1e-6;
can be written more efficient as:
0.2e-6 / sqrt(V(i, 2));

3 件のコメント

Edric Ellis
Edric Ellis 2012 年 10 月 23 日
Unfortunately, MATLAB's debugger cannot debug problems on the matlabpool workers. However, the debugger will work if the OP runs the problematic code including PARFOR with matlabpool closed.
Jan
Jan 2012 年 10 月 23 日
Thanks, Edric. There is a chance that replacing PARFOR by FOR might reveal the cause or the error also.
Yunzhen Chen
Yunzhen Chen 2012 年 10 月 24 日
Thanks Jan and Edric. I'm quite sure the For version codes are correct because they have run over 4000 times with different inputs. There must be something wrong with "parfor". I read the official guidelines for parallel computation, but still has no idea on this error. Parfor is really tricky for me. I hope Mathworks guys can make it more friendly.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by