Products & Services Industries Academia Support User Community Company

Learn more about Parallel Computing Toolbox   

globalIndices - Global indices for local part of codistributed array

Syntax

K = globalIndices(R, dim)
K = globalIndices(R, dim, lab)
[E,F] = globalIndices(R, dim)
[E,F] = globalIndices(R, dim, lab)
K = codist.globalIndices(dim, lab)
[E,F] = codist.globalIndices(dim, lab)

Description

globalIndices tell you the relationship between indices on a local part and the corresponding index range in a given dimension on the distributed array. The globalIndices method on a codistributor object allows you to get this relationship without actually creating the array.

K = globalIndices(R, dim) or K = globalIndices(R, dim, lab) returns a vector K so that getLocalPart(R) = R(...,K,...) in the specified dimension dim on the specified lab. If the lab argument is omitted, the default is labindex.

[E,F] = globalIndices(R, dim) or [E,F] = globalIndices(R, dim, lab) returns two integers E and F so that getLocalPart(R) = R(...,E:F,...) in the specified dimension dim on the specified lab. If the lab argument is omitted, the default is labindex.

K = codist.globalIndices(dim, lab) is the same as K = globalIndices(R, dim, lab), where codist is the codistributor for R, or codist = getCodistributor(R). This allows you to get the global indices for a codistributed array without having to create the array itself.

[E,F] = codist.globalIndices(dim, lab) is the same as [E,F] = globalIndices(R, dim, lab), where codist is the codistributor for R, or codist = getCodistributor(R). This allows you to get the global indices for a codistributed array without having to create the array itself.

Examples

Create a 2-by-22 codistributed array among four labs, and view the global indices on each lab:

spmd
    D = codistributed.zeros(2, 22, codistributor1d(2,[6 6 5 5]));
    if labindex == 1
       K = globalIndices(D, 2);     % returns K = 1:6.
    elseif labindex == 2
       [E,F] = globalIndices(D, 2); % returns E = 7, F = 12.
    end
    K = globalIndices(D, 2, 3);     % returns K = 13:17.
    [E,F] = globalIndices(D, 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 labs and alleviates you from calculating offsets or partitions.

spmd
    siz = [1000, 1000];
    codistr = codistributor1d(2, [], siz);
 
    % Use globalIndices to figure out which columns 
    % each lab should load.
    [firstCol, lastCol] = codistr.globalIndices(2);
 
    % Call user-defined function readRectangleFromFile to
    % load all the values that should go into
    % the local part for this lab.
    labLocalPart = readRectangleFromFile(fileName, ...
                         1, siz(1), firstCol, lastCol);
 
    % With the local part and codistributor,
    % construct the corresponding codistributed array.
    D = codistributed.build(labLocalPart, codistr);
end       

See Also

getLocalPart, labindex

  


Recommended Products

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