Blame src/Matlab/PAPIMatrixVector.m

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