How to get the data from all the workers to a single worker inside SPMD loop
3 ビュー (過去 30 日間)
古いコメントを表示
Nc=3600;
spmd
n1=numlabs;
blocksize = ceil(Nc/n1);
start = (labindex-1)*blocksize + 1;
finish = min(Nc, start+blocksize-1);
for n=finish:-1:start
A_sample=rand(600, 53)
index_cpu = n-start+1;
B_sample (:,:,index_cpu)=A_sample; % each worker has its own copy of B_sample.
end
end
B_collect=cat(3,B_sample{:}); % B_sample is concatenated (collected from all workers) to a single worker outside the SPMD loop
In the above code, consider 4 workers (numlabs) are used inside parallel loop
- A_sample data is copied into B_sample inside SPMD.
- After this, inorder to collect the B_sample data from all the workers to a single variable b_collect, we concatenate the data from all the workers outside the SPMD in B_collect . This concatenation takes a lot of time as Nc value increases (Time expensive)
- In order to avoid the concatenation, I need to assign a variable say C_sample and make all the 4 workers to write to that variable C_sample inside SPMD (instead of writing in its own copy of variable). I think this might avoid the time expense.
I have two questions now :
- How should I do the 3RD point i.e collect the results in C_sample variable inside SPMD (i.e Say C_collect is a global variable and each worker updates in that variable, which will avoid the concatenation issue)
- As each worker (1,2,3,4) has its own copy of B_sample in a composite format, is there any faster way i can send the data of B_sample from workers(2,3,4) to worker 1 inside the SPMD?
I have attached the image and pdf of the same for a better understanding of the question.
2 件のコメント
Walter Roberson
2019 年 6 月 30 日
labSend is the primary method to transmit data between workers.
If you are willing to work out the synchronization issues yourself then the File Exchange contribution sharedmatrix might be useful.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Distributed Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!