function out = hpccPTRANS(m)
%hpccPTRANS HPCC PTRANS Benchmark computation
%   hpccPTRANS(m) creates two random distributed matrices A and B, both of
%   size m-by-m, and computes A' + B.

% Copyright 2018 The MathWorks, Inc.

if nargin < 1
    sz = hpccDataSizes();
    m = sz.PTRANS;
end

dataSizeBytes = 8 * m^2;
hpccBenchmarkStarting("PTRANS", dataSizeBytes);

spmd
    A = codistributed.rand(m, m);
    B = codistributed.rand(m, m);
    
    % Time the transpose
    tic
    Aout = A' + B;
    t = toc;
    
    sres = max(max(abs((Aout - B)' - A))) / eps / m;
    if sres > 16
        error('Failed the HPC PTRANS Benchmark');
    end
end

% Performance in GB/s
tmax = max([t{:}]);
perf = 8 * m * m / tmax / 1e9;
out  = hpccBenchmarkEnd("PTRANS", dataSizeBytes, tmax, perf, "GBperSec");
end
