Non distributed arrays in SPMD
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a distributed array D and a nondistributed C and m workers. I am trying to modify C based on D for all the workers. Here is the code:
X=fopen() %load data from file
C=fopen() %composite array coppied to all workers
[ml,nb,ne]=prange(1,L,matlabpool('size'));
matlabpool 2
spmd D=codistributed(X,codistributor1d(1));
for i=nb(labindex):ne(labindex) %for-loop on local part of D
if D(i,1)>10
C(i)=0
end
end
end
Each worker has a copy of C. The code updates C locally on each worker. I would like to ask if there is any way to update C on all the workers whenever the worker "labindex" set to zero the C(i). One possible way is to gather C on the client but probably will be not so efficient. Thank you in advance for your kind help.
0 Kommentare
Antworten (1)
Jill Reese
am 22 Sep. 2011
I may be misunderstanding what is returned by your prange function, but if you just want the labs to iterate over the entire local part that they own then it's probably easier to use the distributed array interface to work with your data.
% setup X and C
matlabpool 2
spmd
D = codistributed(X, codistributor1d(1));
end
% now use D as a distributed array
for i = 1:size(D,1)
if D(i,1) > 10
C(i) = 0;
end
end
Also, if you don't care how D is distributed over the workers, you can replace the spmd block entirely with
D = distributed(X);
D is then distributed over the workers in whatever way that the Parallel Computing Toolbox chooses.
2 Kommentare
Georgios
am 22 Sep. 2011
Dear Jill thank you for your respond. The prange() functions returns the size of each local part of array D (i.e. size(D)=162,5 then for two workers we have D_Local_1=D(1:81) and D_Local_2=D(82:162). My main problem is array C. Even if I define it prior to SPMD it is coppied to each worker (i.e. 2 copies for two workers-composite array). I am trying to modify both coppies of C whenever any of the workers make a change in C. i.e. if D(10,1)=11 then C_copy_of_worker_1(i)=0 and C_copy_of_worker_2(i)=0. So far each worker updates only its local copy of array C.
Thank you again for your help.
Jill Reese
am 22 Sep. 2011
Georgios,
I'm sorry; my previous answer is clearly not helpful to you. What are the sizes of X and C initially? Knowing the size of the problem will help me provide a better suggestion.
Best,
Jill
Siehe auch
Kategorien
Mehr zu Distributed Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!