PAPI  5.3.0.0
hl_rates.c
Go to the documentation of this file.
00001 /* file hl_rates.c
00002  * This test exercises the four PAPI High Level rate calls:
00003  *    PAPI_flops, PAPI_flips, PAPI_ipc, and PAPI_epc
00004  * flops and flips report cumulative real and process time since the first call,
00005  * and either floating point operations or instructions since the first call.
00006  * Also reported is incremental flop or flip rate since the last call.
00007  *
00008  * PAPI_ipc reports the same cumulative information, substituting total instructions
00009  * for flops or flips, and also reports instructions per (process) cycle as
00010  * a measure of execution efficiency.
00011  *
00012  * PAPI_epc is new in PAPI 5.2. It reports the same information as PAPI_IPC, but 
00013  * for an arbitrary event instead of total cycles. It also reports incremental 
00014  * core and (where available) reference cycles to allow the computation of 
00015  * effective clock rates in the presence of clock scaling like speed step or turbo-boost.
00016  * 
00017  * This test computes a 1000 x 1000 matrix multiply for orders of indexing for
00018  * each of the four rate calls. It also accepts a command line parameter for the
00019  * event to be measured for PAPI_epc. If not provided, PAPI_TOT_INS is measured.
00020  */
00021 
00022 #include "papi_test.h"
00023 
00024 #define ROWS 1000       // Number of rows in each matrix
00025 #define COLUMNS 1000    // Number of columns in each matrix
00026 
00027 static float matrix_a[ROWS][COLUMNS], matrix_b[ROWS][COLUMNS],matrix_c[ROWS][COLUMNS];
00028 
00029 static void init_mat()
00030 {
00031     // Initialize the two matrices
00032     int i, j;
00033     for (i = 0; i < ROWS; i++) {
00034         for (j = 0; j < COLUMNS; j++) {
00035             matrix_a[i][j] = (float) rand() / RAND_MAX;
00036             matrix_b[i][j] = (float) rand() / RAND_MAX;
00037         }
00038     }
00039 
00040 }
00041 
00042 static void classic_matmul()
00043 {
00044     // Multiply the two matrices
00045     int i, j, k;
00046     for (i = 0; i < ROWS; i++) {
00047         for (j = 0; j < COLUMNS; j++) {
00048             float sum = 0.0;
00049             for (k = 0; k < COLUMNS; k++) {
00050                 sum += 
00051                     matrix_a[i][k] * matrix_b[k][j];
00052             }
00053             matrix_c[i][j] = sum;
00054         }
00055     }
00056 }
00057 
00058 static void swapped_matmul()
00059 {
00060     // Multiply the two matrices
00061     int i, j, k;
00062     for (i = 0; i < ROWS; i++) {
00063         for (k = 0; k < COLUMNS; k++) {
00064             for (j = 0; j < COLUMNS; j++) {
00065                 matrix_c[i][j] += 
00066                     matrix_a[i][k] * matrix_b[k][j];
00067             }
00068         }
00069     }
00070 }
00071 
00072 int
00073 main( int argc, char **argv )
00074 {
00075     int retval, event = 0;
00076     float rtime, ptime, mflips, mflops, ipc, epc;
00077     long long flpins, flpops, ins, ref, core, evt;
00078 
00079     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00080 
00081     init_mat();
00082 
00083     printf( "\n----------------------------------\n" );
00084     printf( "PAPI_flips\n");
00085     if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips)  != PAPI_OK )
00086         PAPI_perror( "PAPI_flips" );
00087     printf( "\nStart\n");
00088     printf( "real time:       %f\n", rtime);
00089     printf( "process time:    %f\n", ptime);
00090     printf( "FP Instructions: %lld\n", flpins);
00091     printf( "MFLIPS           %f\n", mflips);
00092     classic_matmul();
00093     if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips)  != PAPI_OK )
00094         PAPI_perror( "PAPI_flips" );
00095     printf( "\nClassic\n");
00096     printf( "real time:       %f\n", rtime);
00097     printf( "process time:    %f\n", ptime);
00098     printf( "FP Instructions: %lld\n", flpins);
00099     printf( "MFLIPS           %f\n", mflips);
00100     swapped_matmul();
00101     if ( PAPI_flips(&rtime, &ptime, &flpins, &mflips)  != PAPI_OK )
00102         PAPI_perror( "PAPI_flips" );
00103     printf( "\nSwapped\n");
00104     printf( "real time:       %f\n", rtime);
00105     printf( "process time:    %f\n", ptime);
00106     printf( "FP Instructions: %lld\n", flpins);
00107     printf( "MFLIPS           %f\n", mflips);
00108 
00109     // turn off flips
00110     if ( PAPI_stop_counters(NULL, 0)  != PAPI_OK )
00111         PAPI_perror( "PAPI_stop_counters" );
00112     printf( "\n----------------------------------\n" );
00113 
00114     printf( "PAPI_flops\n");
00115     if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops)  != PAPI_OK )
00116         PAPI_perror( "PAPI_flops" );
00117     printf( "\nStart\n");
00118     printf( "real time:       %f\n", rtime);
00119     printf( "process time:    %f\n", ptime);
00120     printf( "FP Operations:   %lld\n", flpops);
00121     printf( "MFLOPS           %f\n", mflops);
00122     classic_matmul();
00123     if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops)  != PAPI_OK )
00124         PAPI_perror( "PAPI_flops" );
00125     printf( "\nClassic\n");
00126     printf( "real time:       %f\n", rtime);
00127     printf( "process time:    %f\n", ptime);
00128     printf( "FP Operations:   %lld\n", flpops);
00129     printf( "MFLOPS           %f\n", mflops);
00130     swapped_matmul();
00131     if ( PAPI_flops(&rtime, &ptime, &flpops, &mflops)  != PAPI_OK )
00132         PAPI_perror( "PAPI_flops" );
00133     printf( "\nSwapped\n");
00134     printf( "real time:       %f\n", rtime);
00135     printf( "process time:    %f\n", ptime);
00136     printf( "FP Operations:   %lld\n", flpops);
00137     printf( "MFLOPS           %f\n", mflops);
00138 
00139     // turn off flops
00140     if ( PAPI_stop_counters(NULL, 0)  != PAPI_OK )
00141         PAPI_perror( "PAPI_stop_counters" );
00142     printf( "\n----------------------------------\n" );
00143 
00144     printf( "PAPI_ipc\n");
00145     if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc)  != PAPI_OK )
00146         PAPI_perror( "PAPI_ipc" );
00147     printf( "\nStart\n");
00148     printf( "real time:       %f\n", rtime);
00149     printf( "process time:    %f\n", ptime);
00150     printf( "Instructions:    %lld\n", ins);
00151     printf( "IPC              %f\n", ipc);
00152     classic_matmul();
00153     if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc)  != PAPI_OK )
00154         PAPI_perror( "PAPI_ipc" );
00155     printf( "\nClassic\n");
00156     printf( "real time:       %f\n", rtime);
00157     printf( "process time:    %f\n", ptime);
00158     printf( "Instructions:    %lld\n", ins);
00159     printf( "IPC              %f\n", ipc);
00160     swapped_matmul();
00161     if ( PAPI_ipc(&rtime, &ptime, &ins, &ipc)  != PAPI_OK )
00162         PAPI_perror( "PAPI_ipc" );
00163     printf( "\nSwapped\n");
00164     printf( "real time:       %f\n", rtime);
00165     printf( "process time:    %f\n", ptime);
00166     printf( "Instructions:    %lld\n", ins);
00167     printf( "IPC              %f\n", ipc);
00168 
00169     // turn off ipc
00170     if ( PAPI_stop_counters(NULL, 0)  != PAPI_OK )
00171         PAPI_perror( "PAPI_stop_counters" );
00172     printf( "\n----------------------------------\n" );
00173 
00174     printf( "PAPI_epc\n");
00175     
00176     if ( argc >= 2) {
00177         retval = PAPI_event_name_to_code( argv[1], &event );
00178         if (retval != PAPI_OK) {
00179             PAPI_perror("PAPI_event_name_to_code");
00180             printf("Can't find %s; Using PAPI_TOT_INS\n", argv[1]);
00181             event = 0;
00182         } else {
00183             printf("Using event %s\n", argv[1]);
00184         }
00185     }
00186 
00187     if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc)  != PAPI_OK )
00188         PAPI_perror( "PAPI_epc" );
00189     printf( "\nStart\n");
00190     printf( "real time:       %f\n", rtime);
00191     printf( "process time:    %f\n", ptime);
00192     printf( "Ref Cycles:      %lld\n", ref);
00193     printf( "Core Cycles:     %lld\n", core);
00194     printf( "Events:          %lld\n", evt);
00195     printf( "EPC:             %f\n", epc);
00196     classic_matmul();
00197     if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc)  != PAPI_OK )
00198         PAPI_perror( "PAPI_epc" );
00199     printf( "\nClassic\n");
00200     printf( "real time:       %f\n", rtime);
00201     printf( "process time:    %f\n", ptime);
00202     printf( "Ref Cycles:      %lld\n", ref);
00203     printf( "Core Cycles:     %lld\n", core);
00204     printf( "Events:          %lld\n", evt);
00205     printf( "EPC:             %f\n", epc);
00206     swapped_matmul();
00207     if ( PAPI_epc(event, &rtime, &ptime, &ref, &core, &evt, &epc)  != PAPI_OK )
00208         PAPI_perror( "PAPI_epc" );
00209     printf( "\nSwapped\n");
00210     printf( "real time:       %f\n", rtime);
00211     printf( "process time:    %f\n", ptime);
00212     printf( "Ref Cycles:      %lld\n", ref);
00213     printf( "Core Cycles:     %lld\n", core);
00214     printf( "Events:          %lld\n", evt);
00215     printf( "EPC:             %f\n", epc);
00216 
00217     // turn off epc
00218     if ( PAPI_stop_counters(NULL, 0)  != PAPI_OK )
00219         PAPI_perror( "PAPI_stop_counters" );
00220     printf( "\n----------------------------------\n" );
00221     exit( 1 );
00222 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines