Documentation Center

  • Trials
  • Product Updates


Transfer distributed array data or gpuArray to local workspace


X = gather(A)
X = gather(C, lab)


X = gather(A) can operate inside an spmd statement, pmode, or communicating job to gather together the data of a codistributed array, or outside an spmd statement to gather the data of a distributed array. If you execute this inside an spmd statement, pmode, or communicating job, X is a replicated array with all the data of the array on every worker. If you execute this outside an spmd statement, X is an array in the local workspace, with the data transferred from the multiple workers.

X = gather(distributed(X)) or X = gather(codistributed(X)) returns the original array X.

X = gather(C, lab) converts a codistributed array C to a variant array X, such that all of the data is contained on worker lab, and X is a 0-by-0 empty double on all other workers.

For a gpuArray input, X = gather(A) transfers the data from the GPU to the local workspace.

If the input argument to gather is not a distributed, a codistributed, or a gpuArray, the output is the same as the input.



n = 10;
  C = codistributed(magic(n));
  M = gather(C) % Gather data on all workers
S = gather(C) % Gather data on client

Gather all of the data in C onto worker 1, for operations that cannot be performed across distributed arrays.

n = 10;
  C = codistributed(magic(n));
  out = gather(C, 1);
  if labindex == 1
    % Characteristic sum for this magic square:
    % Ensure that the diagonal sums are equal to the 
    % characteristic sum:
    areDiagonalsEqual = isequal ...
      (trace(out), trace(flipud(out)), characteristicSum)
Lab 1:
  areDiagonalsEqual =

Gather all of the data from a distributed array into D on the client.

n = 10;
D = distributed(magic(n)); % Distribute data to workers
M = gather(D) % Return data to client

Gather the results of a GPU operation to the local workspace.

G = gpuArray(rand(1024,1));
F = sqrt(G); %input and output both gpuArray
W = gather(G); % Return data to client
Name         Size            Bytes  Class

F         1024x1               108  gpuArray
G         1024x1               108  gpuArray
W         1024x1              8192  double

More About

expand all




See Also

| | | |

Was this topic helpful?