Blame src/Matlab/PAPIMatrixMatrix.m

Packit 577717
function PAPIMatrixMatrix
Packit 577717
Packit 577717
% Compute a Matrix Matrix multiply 
Packit 577717
% on square arrays sized from 50 to 500,
Packit 577717
% in steps of 50. 
Packit 577717
%
Packit 577717
% Use the PAPI mex function with two different methods:
Packit 577717
% - The PAPI High Level flops call
Packit 577717
% - PAPI High Level start/stop calls
Packit 577717
%
Packit 577717
% For each size, display:
Packit 577717
% - number of floating point operations
Packit 577717
% - theoretical number of operations
Packit 577717
% - difference
Packit 577717
% - per cent error
Packit 577717
% - mflops/s
Packit 577717
Packit 577717
fprintf(1,'\nPAPI Matrix Matrix Multiply Test');
Packit 577717
fprintf(1,'\nUsing the High Level PAPI("flops") call');
Packit 577717
fprintf(1,'\n%12s %12s %12s %12s %12s %12s\n', 'n', 'ops', '2n^3', 'difference', '% error', 'mflops')
Packit 577717
for n=50:50:500,
Packit 577717
    a=rand(n);b=rand(n);c=rand(n);
Packit 577717
    PAPI('stop'); % reset the counters to zero
Packit 577717
    PAPI('flops'); % start counting flops
Packit 577717
    c=c+a*b;
Packit 577717
    [count, mflops] = PAPI('flops'); % read the flops data
Packit 577717
    fprintf(1,'%12d %12d %12d %12d %12.2f %12.2f\n',n,count,2*n^3,count - 2*n^3, (1.0 - ((2*n^3) / count)) * 100,mflops)
Packit 577717
end
Packit 577717
PAPI('stop');
Packit 577717
Packit 577717
fprintf(1,'\nPAPI Matrix Matrix Multiply Test');
Packit 577717
fprintf(1,'\nUsing PAPI start and stop');
Packit 577717
fprintf(1,'\n%12s %12s %12s %12s %12s %12s\n', 'n', 'ops', '2n^3', 'difference', '% error', 'flops/cycle')
Packit 577717
for n=50:50:500,
Packit 577717
    a=rand(n);b=rand(n);c=rand(n);
Packit 577717
    PAPI('start', 'PAPI_TOT_CYC', 'PAPI_FP_OPS');
Packit 577717
    c=c+a*b;
Packit 577717
    [cyc, ops] = PAPI('stop');
Packit 577717
    fprintf(1,'%12d %12d %12d %12d %12.2f %12.6f\n',n,ops,2*n^3,ops - 2*n^3, (1.0 - ((2*n^3) / ops)) * 100,ops/cyc)
Packit 577717
end