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,...)
在指定工作单元上的共存分布式数组 dim
的指定维度 C
中。如果省略 lab
参量,则默认为 spmdIndex
。
[E,F] = globalIndices(C,dim)
或 [E,F] = globalIndices(C,dim,lab)
返回两个整数 E
和 F
,使得共存分布式数组 getLocalPart(C) = C(...,E:F,...)
中指定维度 C
的 dim
在指定的工作单元上。如果省略 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)
的协同分布器。这使得您可以获取共存分布式数组的全局索引,而无需创建数组本身。
示例
在四个工作单元之间创建一个 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 中推出