function cellArrayOfOutputs = allToAll(cellArrayOfInputs)
; %#ok<NOSEM> % Undocumented

%   This function takes a cell vector of data to be exchanged with other 
%   workers and returns a cell row vector of data received from other
%   workers in an all-to-all communication

%   Copyright 2011-2022 The MathWorks, Inc.

    cellArrayOfOutputs = cell(1, spmdSize);
    mwTag = 31979;
    
    % cellArrayOfOutputs(i) contains the data belonging to me that have
    % been received from worker i.
    for offset = 0:spmdSize-1
        workerTo = mod(spmdIndex + offset - 1, spmdSize) + 1;
        workerFrom = mod(spmdIndex - offset - 1, spmdSize) + 1;
        cellArrayOfOutputs(workerFrom) = spmdSendReceive(workerTo, workerFrom, ...
           cellArrayOfInputs(workerTo), mwTag);
    end
end

