| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Parallel Computing Toolbox |
| Contents | Index |
| Learn more about Parallel Computing Toolbox |
X = gather(A)
X = gather(C, lab)
X = gather(A) can operate inside an spmd statement, pmode, or parallel 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 parallel job, X is replicated array with all the data of the array on every lab. If you execute this outside an spmd statement, X is an array in the local workspace, with the data transferred from the multiple labs.
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 lab lab, and X is a 0-by-0 empty double on all other labs.
Note that gather assembles the codistributed or distributed array in the workspaces of all the labs on which it executes, or on the MATLAB client, respectively, but not both. If you are using gather within an spmd statement, the gathered array is accessible on the client via its corresponding Composite object; see Accessing Data with Composites. If you are running gather in a parallel job, you can return the gathered array to the client as an output argument from the task.
As the gather function requires communication between all the labs, you cannot gather data from all the labs onto a single lab by placing the function inside a conditional statement such as if labindex == 1.
Distribute a magic square across your labs, then gather the whole matrix onto every lab and then onto the client. This code results in the equivalent of M = magic(n) on all labs and the client.
n = 10;
spmd
D = codistributed(magic(n));
M = gather(D) % Gather data on all labs
end
M = gather(D) % Gather data on clientGather all of the data in D onto lab 1, so that it can be saved from there.
n = 10;
spmd
D = codistributed(magic(n));
out = gather(D, 1);
if labindex == 1
save data.mat out;
end
endGather all of the data from a distributed array into D on the client.
n = 10; D = distributed(magic(n)); % Distribute data to labs M = gather(D) % Return data to client
![]() | for | gcat | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |