Documentation

globalIndices

Global indices for local part of codistributed array

Syntax

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)

Description

globalIndicestells you the relationship between indices on a local part and the corresponding index range in a given dimension on the codistributed array. TheglobalIndicesmethod on a codistributor object allows you to get this relationship without actually creating the array.

K = globalIndices(C,dim)orK = globalIndices(C,dim,lab)returns a vectorKso thatgetLocalPart(C) = C(...,K,...)in the specified dimensiondimof codistributed arrayCon the specified worker. If thelabargument is omitted, the default islabindex.

[E,F] = globalIndices(C,dim)or[E,F] = globalIndices(C,dim,lab)returns two integersEandFso thatgetLocalPart(C) = C(...,E:F,...)of codistributed arrayCin the specified dimensiondimon the specified worker. If thelabargument is omitted, the default islabindex.

K = globalIndices(codist,dim,lab)is the same asK = globalIndices(C,dim,lab), wherecodistis the codistributor to be used forC, orcodist = 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), wherecodistis the codistributor to be used forC, orcodist = getCodistributor(C). 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 workers, and view the global indices on each lab:

spmdC = zeros(2,22,codistributor1d(2,[6 6 5 5]));iflabindex == 1 K = globalIndices(C,2)% returns K = 1:6.elseiflabindex == 2 [E,F] = globalIndices(C,2)% returns E = 7, F = 12.endK = globalIndices(C,2,3)% returns K = 13:17.(E, F) = globalIndices (C、2、4)% returns E = 18, F = 22.end

UseglobalIndicesto load data from a file and construct a codistributed array distributed along its columns, i.e., dimension 2. Notice howglobalIndicesmakes the code not specific to the number of workers and alleviates you from calculating offsets or partitions.

spmdsiz = [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

Introduced in R2008a

Was this topic helpful?