Sharing data and computations across processors
1 view (last 30 days)
Show older comments
so I have this code which I am trying to run over a cluster. I used spmd and distributed for (drange). It worked fine on local cluster but depolying it to remote cluster requires some work and I need to share the function test between workers so I used
addArrachedFiles('<path to the function>/test.m');
Basically the function test has two input variables a and b (this is a simplifeid code used for testing but actually the code is complex). I got an error "undefined variables a and b. I have seen some people use parfeval to evaluate functions. Can I use parfeval with distributed spmd and for-drange ? if not, what is the best way to code this program.
function [t,n]=test(a,b)
x=zeros(size(b));
% for i=1:size(a,2)
% c=a(i)*exp(-b);
% x(i)=sum(c);
%
% end
t=sum(log(a*b));
n=mean(a*b);
a=rand(1,100);
b=rand(3,4e3);
y=zeros(3,100);
x=zeros(3,100);
% y=[1 2;3 4;5 6];
% x=[7 8;9 10;11 12];
spmd
C1 = codistributed(x,codistributor1d(2));
C2 = codistributed(y,codistributor1d(2));
C3 = codistributed(a,codistributor1d(2));
getLocalPart(C1)
getLocalPart(C2)
%getLocalPart(C3)
for i=drange(1:100)
[C2(1,i),C1(1,i)]=test(C3(i),b(1,:)) ;
y(1,i)=u1;x(1,i)=c1;
[C2(2,i),C1(2,i)]=test(C3(i),b(2,:)) ;
[C2(3,i),C1(3,i)]=test(C3(i),b(3,:)) ;
y(2,i)=u2;x(2,i)=c2;
y(3,i)=u3;x(3,i)=c3;
end
end
r1=gather(C1)
r2=gather(C2)
0 Comments
Answers (0)
See Also
Categories
Find more on Parallel Computing Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!