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