主要内容

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

codistributed.build

从分布式数据创建共存分布式数组

语法

D = codistributed.build(L,codist)
D = codistributed.build(L,codist,'noCommunication')

说明

D = codistributed.build(L,codist)getLocalPart(D) = L 形成一个共存分布式数组。共存分布式数组 D 的创建方式就像您组合了本地数组 L 的所有副本一样。分布方案由 codist 指定。全局错误检查确保本地部分符合指定的分布方案。有关构造 codistributor 对象的信息,请参阅 codistributor1dcodistributor2dbc 的参考页。

D = codistributed.build(L,codist,'noCommunication') 构建一个共存分布式数组,但不执行任何用于错误检查的工作单元间的通信。

codist 必须完整,您可以通过调用 codist.isComplete() 来检查。本地部分 L 的大小和结构要求取决于 codist 的类。对于一维和二维块循环协同分布器,L 在所有工作单元上必须具有相同的类和稀疏性。此外,本地部分 L 必须表示 globalIndices 方法在 codist 上描述的区域。

示例

创建一个大小为 1001×1001 的共存分布式数组,使得列 ii 包含值 ii

spmd
    N = 1001;
    globalSize = [N,N];
    % Distribute the matrix over the second dimension (columns),
    % and let the codistributor derive the partition from the 
    % global size.
    codistr = codistributor1d(2, ...
                 codistributor1d.unsetPartition,globalSize)
 
    % On 4 workers, codistr.Partition equals [251,250,250,250].
    % Allocate storage for the local part.
    localSize = [N, codistr.Partition(spmdIndex)];
    L = zeros(localSize);
    
    % Use globalIndices to map the indices of the columns 
    % of the local part into the global column indices.
    globalInd = codistr.globalIndices(2); 
    % On 4 workers, globalInd has the values:
    % 1:251    on worker 1
    % 252:501  on worker 2
    % 502:751  on worker 3
    % 752:1001 on worker 4
    
    % Initialize the columns of the local part to 
    % the correct value.
    for localCol = 1:length(globalInd)
        globalCol = globalInd(localCol);
        L(:,localCol) = globalCol;
    end
    D = codistributed.build(L,codistr)
end

版本历史记录

在 R2009b 中推出