User`s guide

codistributed.build
11-27
% Distribute the matrix over the second dimension (columns),
% and let the codistributor derive the partition from the
% global size.
codistr = codistributor1d(2, ...
codistributor1d.unsetPartition, globalSize)
% On 4 workers, codistr.Partition equals [251, 250, 250, 250].
% Allocate storage for the local part.
localSize = [N, codistr.Partition(labindex)];
L = zeros(localSize);
% Use globalIndices to map the indices of the columns
% of the local part into the global column indices.
globalInd = codistr.globalIndices(2);
% On 4 workers, globalInd has the values:
% 1:251 on worker 1
% 252:501 on worker 2
% 502:751 on worker 3
% 752:1001 on worker 4
% Initialize the columns of the local part to
% the correct value.
for localCol = 1:length(globalInd)
globalCol = globalInd(localCol);
L(:, localCol) = globalCol;
end
D = codistributed.build(L, codistr)
end
See Also
codistributor1d | codistributor2dbc | gather | globalIndices |
getLocalPart | redistribute | size | subsasgn | subsref