Main Content

本页采用了机器翻译。点击此处可查看英文原文。

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) 返回一个向量 K,使得 getLocalPart(C) = C(...,K,...) 在指定工作进程上的同分布数组 C 的指定维度 dim 中。如果省略 lab 参量,则默认为 spmdIndex

[E,F] = globalIndices(C,dim)[E,F] = globalIndices(C,dim,lab) 返回两个整数 EF,使得同分布数组 C 中指定维度 dimgetLocalPart(C) = C(...,E:F,...) 在指定的工作进程上。如果省略 lab 参量,则默认为 spmdIndex

K = globalIndices(codist,dim,lab)K = globalIndices(C,dim,lab) 相同,其中 codist 是用于 Ccodist = getCodistributor(C) 的协同分配器。这使得您可以获取协同分布数组的全局索引,而无需创建数组本身。

[E,F] = globalIndices(codist,dim,lab)[E,F] = globalIndices(C,dim,lab) 相同,其中 codist 是用于 Ccodist = getCodistributor(C) 的协同分配器。这使得您可以获取协同分布数组的全局索引,而无需创建数组本身。

示例

在四个工作进程之间创建一个 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 中推出

另请参阅

|