I have a spmd block inside a for-loop. I need a 2*9 vector called Aa to be distributed between three or more workers, some calculations are performed and as a result, few matrices and vectors are generated. then the matrices of each worker and all workers are concatenated together. The resulted matrix and vector are converted to double and a new spmd block is started. The error "Subscripted assignment dimension mismatch" is shown when I run the code. Can I increase the number of workers? Here is some part of the code:
Thank you in advance
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
The following code works well for that purpose.
Aa=[0 0; 0 1; 0 2; 1 0; 1 1; 1 2; 2 0; 2 1; 2 2 ];
spmd (3)
for ss=1:3 % To assign three pairs of Aa to any worker
if (labindex==1)
a=Aa(ss,1);
b=Aa(ss,2);
elseif (labindex==2)
a=Aa(3+ss,1);
b=Aa(3+ss,2);
else
a=Aa(6+ss,1);
b=Aa(6+ss,2);
end
% the remaining commands with some modifications
end