globalIndices
対話型分散配列のローカル部分のグローバル インデックス
構文
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
は、対話型分散配列のローカル部分のインデックスと、その指定次元における対応するインデックス範囲との関係を示します。対話型分散オブジェクトに対し globalIndices
メソッドを使用すると、実際に配列を作成せずにこの関係を取得できます。
K = globalIndices(C,dim)
または K = globalIndices(C,dim,lab)
は、指定されたワーカーの対話型分散配列 C
の指定された次元 dim
において getLocalPart(C) = C(...,K,...)
となるようなベクトル K
を返します。引数 lab
を省略した場合、その既定値は spmdIndex
です。
[E,F] = globalIndices(C,dim)
または [E,F] = globalIndices(C,dim,lab)
は、指定されたワーカーの対話型分散配列 C
の指定された次元 dim
において getLocalPart(C) = C(...,E:F,...)
となる 2 つの整数 E
と F
を返します。引数 lab
を省略した場合、その既定値は spmdIndex
です。
K = globalIndices(codist,dim,lab)
は K = globalIndices(C,dim,lab)
と同じ結果になります。ここで、codist
は C
に対して使用する対話型分散であり、つまり、codist = getCodistributor(C)
です。これにより、対話型分散配列自体を作成せずに対話型分散配列のグローバル インデックスを取得できるようになります。
[E,F] = globalIndices(codist,dim,lab)
は [E,F] = globalIndices(C,dim,lab)
と同じ結果になります。ここで、codist
は C
に対して使用する対話型分散であり、つまり、codist = getCodistributor(C)
です。これにより、対話型分散配列自体を作成せずに対話型分散配列のグローバル インデックスを取得できるようになります。
例
4 つのワーカーに分散する 2 行 22 列の対話型分散配列を作成し、各ラボのグローバル インデックスを表示します。
spmd C = zeros(2,22,codistributor1d(2,[6 6 5 5])); if spmdIndex == 1 K = globalIndices(C,2) % returns K = 1:6. elseif spmdIndex == 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
globalIndices
を使用してファイルからデータを読み込み、列、すなわち次元 2 に沿って分散される対話型分散配列を作成します。globalIndices
により、コードがワーカー数に固有のものではなくなり、オフセットや分割を計算せずに済むようになる点に注目してください。
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
バージョン履歴
R2008a で導入