Blame src/examples/PAPI_get_real_cyc.c

Packit 577717
/******************************************************************************
Packit 577717
 * This is an example to show how to use low level function PAPI_get_real_cyc *
Packit 577717
 * and PAPI_get_real_usec.                                                    *
Packit 577717
 ******************************************************************************/
Packit 577717
Packit 577717
#include <stdio.h>
Packit 577717
#include <stdlib.h>
Packit 577717
#include "papi.h" /* This needs to be included every time you use PAPI */
Packit 577717
Packit 577717
int your_slow_code()
Packit 577717
{
Packit 577717
   int i,tmp;
Packit 577717
Packit 577717
   for(i=1; i<20000; i++)
Packit 577717
   {
Packit 577717
      tmp=(tmp+100)/i;
Packit 577717
   }
Packit 577717
   return 0;
Packit 577717
}
Packit 577717
Packit 577717
int main()
Packit 577717
{
Packit 577717
   long long s,s1, e, e1;
Packit 577717
   int retval;
Packit 577717
Packit 577717
Packit 577717
   /****************************************************************************
Packit 577717
   *  This part initializes the library and compares the version number of the *
Packit 577717
   * header file, to the version of the library, if these don't match then it  *
Packit 577717
   * is likely that PAPI won't work correctly.If there is an error, retval     *
Packit 577717
   * keeps track of the version number.                                        *
Packit 577717
   ****************************************************************************/
Packit 577717
Packit 577717
   if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
Packit 577717
   {
Packit 577717
      printf("Library initialization error! \n");
Packit 577717
      exit(1);
Packit 577717
   }
Packit 577717
        
Packit 577717
   /* Here you get initial cycles and time */
Packit 577717
   /* No error checking is done here because this function call is always 
Packit 577717
      successful */
Packit 577717
Packit 577717
   s = PAPI_get_real_cyc();
Packit 577717
Packit 577717
   your_slow_code();
Packit 577717
  
Packit 577717
   /*Here you get final cycles and time    */
Packit 577717
   e = PAPI_get_real_cyc();
Packit 577717
Packit 577717
   s1= PAPI_get_real_usec();
Packit 577717
Packit 577717
   your_slow_code();
Packit 577717
Packit 577717
   e1= PAPI_get_real_usec();
Packit 577717
Packit 577717
   printf("Wallclock cycles  : %lld\nWallclock time(ms): %lld\n",e-s,e1-s1);
Packit 577717
Packit 577717
   /* clean up */
Packit 577717
   PAPI_shutdown();
Packit 577717
Packit 577717
   exit(0);
Packit 577717
}
Packit 577717
Packit 577717
 
Packit 577717