Global indices for local part of codistributed array
K = globalIndices(C,dim)
K
= globalIndices(C,dim,lab)
[E,F] = globalIndices(C,dim)
[E,F]
= globalIndices(C,dim,lab)
K = globalIndices(codist,dim,lab)
[E,F] = globalIndices(codist,dim,lab)
globalIndices
tells you the relationship
between indices on a local part and the corresponding index range
in a given dimension on the codistributed array. The globalIndices
method
on a codistributor object allows you to get this relationship without
actually creating the array.
K = globalIndices(C,dim)
or K
= globalIndices(C,dim,lab)
returns a vector K
so
that getLocalPart(C) = C(...,K,...)
in the specified
dimension dim
of codistributed array C
on
the specified worker. If the lab
argument is omitted,
the default is labindex
.
[E,F] = globalIndices(C,dim)
or [E,F]
= globalIndices(C,dim,lab)
returns two integers E
and F
so
that getLocalPart(C) = C(...,E:F,...)
of codistributed
array C
in the specified dimension dim
on
the specified worker. If the lab
argument is omitted,
the default is labindex
.
K = globalIndices(codist,dim,lab)
is the
same as K = globalIndices(C,dim,lab)
, where codist
is
the codistributor to be used for C
, or codist
= getCodistributor(C)
. This allows you to get the global
indices for a codistributed array without having to create the array
itself.
[E,F] = globalIndices(codist,dim,lab)
is
the same as [E,F] = globalIndices(C,dim,lab)
, where codist
is
the codistributor to be used for C
, or codist
= getCodistributor(C)
. This allows you to get the global
indices for a codistributed array without having to create the array
itself.
Create a 2-by-22 codistributed array among four workers, and view the global indices on each lab:
spmd C = zeros(2,22,codistributor1d(2,[6 6 5 5])); if labindex == 1 K = globalIndices(C,2) % returns K = 1:6. elseif labindex == 2 [E,F] = globalIndices(C,2) % returns E = 7, F = 12. end K = globalIndices(C,2,3) % returns K = 13:17. [E,F] = globalIndices(C,2,4) % returns E = 18, F = 22. end
Use globalIndices
to load data from a file
and construct a codistributed array distributed along its columns,
i.e., dimension 2. Notice how globalIndices
makes
the code not specific to the number of workers and alleviates you
from calculating offsets or partitions.
spmd siz = [1000,1000]; codistr = codistributor1d(2,[],siz); % Use globalIndices to figure out which columns % each worker should load. [firstCol,lastCol] = globalIndices(codistr,2); % Call user-defined function readRectangleFromFile to % load all the values that should go into % the local part for this worker. labLocalPart = readRectangleFromFile(fileName, ... 1,siz(1),firstCol,lastCol); % With the local part and codistributor, % construct the corresponding codistributed array. C = codistributed.build(labLocalPart,codistr); end