|
PAPI
5.0.1.0
|
00001 /****************************************************************************** 00002 * This is an example to show how to use low level function PAPI_get_real_cyc * 00003 * and PAPI_get_real_usec. * 00004 ******************************************************************************/ 00005 00006 #include <stdio.h> 00007 #include <stdlib.h> 00008 #include "papi.h" /* This needs to be included every time you use PAPI */ 00009 00010 int your_slow_code() 00011 { 00012 int i,tmp; 00013 00014 for(i=1; i<20000; i++) 00015 { 00016 tmp=(tmp+100)/i; 00017 } 00018 return 0; 00019 } 00020 00021 int main() 00022 { 00023 long long s,s1, e, e1; 00024 int retval; 00025 00026 00027 /**************************************************************************** 00028 * This part initializes the library and compares the version number of the * 00029 * header file, to the version of the library, if these don't match then it * 00030 * is likely that PAPI won't work correctly.If there is an error, retval * 00031 * keeps track of the version number. * 00032 ****************************************************************************/ 00033 00034 if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT ) 00035 { 00036 printf("Library initialization error! \n"); 00037 exit(1); 00038 } 00039 00040 /* Here you get initial cycles and time */ 00041 /* No error checking is done here because this function call is always 00042 successful */ 00043 00044 s = PAPI_get_real_cyc(); 00045 00046 your_slow_code(); 00047 00048 /*Here you get final cycles and time */ 00049 e = PAPI_get_real_cyc(); 00050 00051 s1= PAPI_get_real_usec(); 00052 00053 your_slow_code(); 00054 00055 e1= PAPI_get_real_usec(); 00056 00057 printf("Wallclock cycles : %lld\nWallclock time(ms): %lld\n",e-s,e1-s1); 00058 00059 /* clean up */ 00060 PAPI_shutdown(); 00061 00062 exit(0); 00063 } 00064 00065 00066