How to perform the inverse operation of "spmdCat" in parallel computing

조회 수: 7 (최근 30일)
siyu guo
siyu guo 2025년 3월 26일
답변: Edric Ellis 2025년 3월 27일
In the parallel computing toolbox, the function "spmdCat" is responsible for concatenating arrays on spmd workers, for example:
B = spmdCat(A) horizontally concatenates the array A defined on each worker running an spmd block or communicating job.
Edit and run the following code:"spmdCat" in Matlab help center
parpool(4);
spmd
B = spmdCat(spmdIndex);
end
B{1}
The results are as follows:
ans =
1 2 3 4
However, there is no function in the parallel computing toolbox that performs the spmdCat inverse operation (that is, the "scatter" operation which can split arrays into spmd workers).
To implement the scatter function, I wrote the following code: "spmdsendreceive"
r_part=spmdSendReceive(spmdIndex,spmdIndex,A(i));
% The arrays A(a replicable varible on spmdworkers) to be scattered is divided into
% n(n=spmdSize) parts according to i(i is a row vector),and then A(i) is sent and
% received (in paralled?) using spmdSendReceive.
So, my question is whether the above code can be implemented in a parallel way for the "scatter" operation, and if there are other more efficient implementation methods?
Sincerely looking forward for your answers.

답변 (1개)

Edric Ellis
Edric Ellis 2025년 3월 27일
A "scatter" method isn't exposed directly, but you can achieve the same thing using the codistributed constructor, like this:
spmd
if spmdIndex == 1
% Set up "x" to have the value we want on worker 1
x = rand(20);
else
% This value will be ignored
x = [];
end
% This will scatter the contents of "x" to all workers
d = codistributed(x, 1)
end

카테고리

Help CenterFile Exchange에서 Distributed Arrays에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by