I am working on a parfor loop in MatLab R2021b, shown below. But there are errors: Valid indices for 'Time_h1' and 'HD_Top' are restricted in PARFOR loops. I would like to how to solve this issue? Thanks.
parfor j = 1:nk2
if abs(ID_sat) < 1e-5
T_mesh(nt,j) = 11;
Time_h1 (1:11,j) = 0:t_final/10:t_final; % error: restricted in PARFOR loops
HD_Top (1:11,j) = 0; % error: restricted in PARFOR loops
else
...
end
end

 採用された回答

Walter Roberson
Walter Roberson 2022 年 3 月 10 日

0 投票

parfor j = 1:nk2
if abs(ID_sat) < 1e-5
T_mesh(nt,j) = 11;
h1 = Time_h1(:,j);
HT = HD_top(:,j);
h1(1:11) = 0:t_final/10:t_final;
Time_h1(:,j) = h1;
HT(1:11) = 0;
HD_Top(:,j) = HT;
else
...
end
end

4 件のコメント

xiaohuo
xiaohuo 2022 年 3 月 10 日
Coud you please explain it? do you meant that it solve the issue using temporary variables?
xiaohuo
xiaohuo 2022 年 3 月 10 日
Another issue in parfor loop
in a parfor loop. variable "Time_h1" and "HD_Top" are indexed in different wats, potentiall causing dependences between iterations.
Would you please give some advice to solve this issue?
parfor j = 1:nk
if abs(ID_sat) < 1e-5
...
else
% "Size_surf_flux" Aray
% Size_surf_flux(1): Numer of row
% Size_surf_flux(2): Numer of column
Size_surf_flux = size (Surface_flux);
T_mesh(nt,j) = Size_surf_flux(1);
T_mesh00 = T_mesh(nt,j); % T_mesh: row number of the array of "Surface_flux"
Time_h1 (1:T_mesh00,j) = Surface_flux(1:T_mesh00,1); % Error: Time_h1
HD_Top(1:T_mesh00,j) = Surface_flux(1:T_mesh00,4); % Error: HD_Top
end
end
Walter Roberson
Walter Roberson 2022 年 3 月 10 日
When you assign to an array that is indexed by a parfor variable, each index has to be either scalar or the : operator; when you read from an array that is indexed by a parfor variable, each index has to be either scalar or the : operator.
t1 = Time_h1(:,j); %okay because it uses :
t1(1:T_mesh00) = Surface_flux(1:T_mesh00,1); %okay because it is not indexed by j
Time_h1(:,j) = t1; %okay because it uses :
xiaohuo
xiaohuo 2022 年 3 月 10 日
Thanks.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 3 月 10 日

コメント済み:

2022 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by