個々のワーカーでそれぞれサイズ (300,1) の 4 つの配列を生成する場合は、次のようにすることをお勧めします。私のコンピューター/Matlab プールには 4 つのコアがあることに注意してください。
clc
clear
spmd
RandomArray = rand(300,1); % Matlab automatically creates a (300,1) array in each worker.
end
FinalArray = [RandomArray{:}]; % Concatenate everything outside of the spmd block.
whos % Check the results
Name Size Bytes Class Attributes
FinalArray 300x4 9600 double
RandomArray 1x4 1145 Composite
ご覧のとおり、FinalArray のサイズは (300,4) です。上記のコードでは、2 番目の spmd ブロックにすべてをまとめるのは非常に面倒です。各ワーカーは他のワーカーの内容を認識しておらず、変数を使用していないワーカーでは各変数が定義されていないためです。申し訳ありませんが、正しい用語はわかりませんが、ドキュメントを読んでより良い説明を得ることができます:)
編集:
あなたのコメントに答えるために、ここに簡単な例があります。うまくいけば、これはあなたが意図したものです:)
clc
clear
% Define different variables.
w = ones(1,10);
x = 1:10;
y = x/2;
z = rand(1,10);
% Use different functions in each worker. Of course you could use the same function with different inputs.
spmd
if labindex==1
a = w;
end
if labindex==2
b = sin(x);
end
if labindex==3
c = y.^2;
end
if labindex==4
d = 4*z;
end
end
% This is the important part
FinalArray = [a{1} ;b{2}; c{3} ;d{4}];
whos
whos の出力は次のとおりです。
Name Size Bytes Class Attributes
FinalArray 4x10 320 double
a 1x4 497 Composite
b 1x4 497 Composite
c 1x4 497 Composite
d 1x4 497 Composite
w 1x10 80 double
x 1x10 80 double
y 1x10 80 double
z 1x10 80 double