我在 for 循环中有一个 spmd 块。我需要一个名为 Aa 的 2*9 向量分布在三个或更多工作人员之间,执行一些计算,结果生成的矩阵和向量很少。然后将每个工人和所有工人的矩阵连接在一起。结果矩阵和向量被转换为双精度并启动一个新的 spmd 块。运行代码时显示错误“下标分配维度不匹配”。我可以增加工人的数量吗?这是代码的一部分:
先感谢您
Aa=[0 0; 0 1; 0 2; 1 0; 1 1; 1 2; 2 0; 2 1; 2 2 ];
for n=3:TGponts1
% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
% In this part, some calculation is done on Good_path_1 and R2_1
% and a new Good_path1_1 and R_1 and s1_1 are defined
% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
q_1=0; q_2=0;
nn1=n-1; nn2=2*n-2;
spmd (3)
for ss=1:3 % To assign three pairs of Aa to any worker
if (ss == 1)
a=Aa(labindex,1);
b=Aa(labindex,2);
elseif (ss == 2)
a=Aa(labindex+3,1);
b=Aa(labindex+3,2);
else
a=Aa(labindex+6,1);
b=Aa(labindex+6,2);
end
Sum1=single(0);
% Here, some calculation is done.
if p>thr_Wght
q_1=q_1+1;
if n<=n_c1
Good_path1_1(q_1,1:2*n)=
[a,Good_path_1(k_1,1:nn1),b,Good_path_1(k_1,n:nn2)];
else
Good_path1_1(q_1,1:L)=
[a,Good_path_1(k_1,1:n_c),b,Good_path_1(k_1,n_c1:n_c2)];
end
R_1(q_1)=R3;
Sum1=Sum1+R3;
end
% Each worker performs these commands three times.
Good_path1_1(q_1+1:s1_1,:)=[];
R_1(1,q_1+1:s1_1)=[];
% Is it true to write like this to avoid that the third
% (second) Good_path1_1 and R_1 are not replaced with
the second (first) one?
Good_path1_1ew(:,:,ss)=Good_path1_1;
R_1ew(:,ss)= R_1;
% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
end
end
% Here all the Good_path1_1 of each worker and all workers are concatenated
Good_path1_1 = gcat(Good_path1_1ew, 1);
R_1=gcat(R_1ew, 1);
% &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Good_path1_1=str2double(Good_path1_1);
R_1=str2double(R_1);
% Here Good_path1_1 and R_1 are substituted into Good_path_1 and R2_1
Good_path_1=Good_path1_1;
R2_1=R_1;
end