Changing the size of SPMD

4 views (last 30 days)
Mehdi
Mehdi on 25 Jan 2015
Edited: Rik on 14 Oct 2020
I need to close spmd and open another spmd of a smaller size repeatedly, but I receive this error that there exists an active spmd. I need to open and close spmds in a loop. What I am actually doing to get my code working is closing and opening the pool every time at the beginning of the loop, which is really inefficient. Also, I am using 2012b and it does not recognize "delete(gcp)".
I would appreciate your help!
  1 Comment
Mehdi
Mehdi on 27 Jan 2015
Edited: Mehdi on 30 Jan 2015
This is a kind of emergency for me! Here is the loop that I use SPMD in it. As you see I have cleared all the composite, yet the same error:
for io=1:Q+1
display(['io = ' num2str(io)]);
% matlabpool close
N_spmdOld=N_spmd;
if io==Q+1
N_spmd=R;
end
spmd (N_spmd)
ak=xi((io-1)*N_spmdOld+labindex);
bk=xi((io-1)*N_spmdOld+labindex+1);
K1=(bk-ak)/2;
K2=(bk+ak)/2;
Cijk_E=CPU_gPCCijk(M,p_E,Type);
PSI2Norm_E=CPU_Psi2Norm(M,p_E,Type);
A_E=K1*Cijk_E{2}+K2*Cijk_E{1};
for i=1:Size_E
A_E(i,:)=-A_E(i,:)/PSI2Norm_E(i);
end
end
odefun_E=Composite();
for k=1:N_spmd
B_E=A_E{k};
odefun_E{k}=@(t,u)(B_E*u);
end
spmd (N_spmd)
u0_E=zeros(Size_E,1);
u0_E(1)=U0;
options = odeset('MaxStep',(tn-t0)/(numt));
[~,U_E]=ode45(odefun_E,T,u0_E,options);
MeanE=U_E(:,1);
VarE=zeros(numt,1);
for i=1:numt
sum=0;
for j=2:Size_E
sum=sum+PSI2Norm_E(j)*U_E(i,j)^2;
end
VarE(i)=sum;
end
end
for k=1:N_spmd
MeanME=MeanME+MeanE{k};
end
for k=1:N_spmd
s=s+1;
UE=U_E{k};
UEsaved(:,s)=UE(:,1);
end
for k=1:N_spmd
VarME=VarME+VarE{k};
end
clear labindex ak bk K1 K2 Cijk_E PSI2Norm_E A_E B_E odefun_E u0_E options U_E sum MeanE VarE i j k
end

Sign in to comment.

Answers (1)

Edric Ellis
Edric Ellis on 26 Jan 2015
You probably have existing distributed arrays or Composite objects in your workspace - these prevent you from changing the size of the active SPMD context. If you clear all those from your workspace, you should be able to proceed.
  4 Comments
micholeodon
micholeodon on 13 Oct 2020
Edited: Rik on 14 Oct 2020
Here you can find a way to clear all Composites in your workspace.
Edit Rik:
The contents of that page show this solution:
D = whos();
D = D(arrayfun(@(d) strcmp(d.class,'yourclassname'),D));
clear(D.name)
micholeodon
micholeodon on 13 Oct 2020
Also avoid syntax with tildas like:
[outvar1, ~] = some_function(arg1, arg2);
do instead
outvar1 = some_function(arg1, arg2);
because it can trigger context error as well.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!