PAPI_add_remove_events.c File Reference

Include dependency graph for PAPI_add_remove_events.c:

Go to the source code of this file.

Defines

#define NUM_EVENT   2
#define THRESHOLD   100000
#define ERROR_RETURN(retval)   { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Functions

int main ()

Define Documentation

#define ERROR_RETURN ( retval   )     { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Definition at line 17 of file PAPI_add_remove_events.c.

#define NUM_EVENT   2

Definition at line 15 of file PAPI_add_remove_events.c.

#define THRESHOLD   100000

Definition at line 16 of file PAPI_add_remove_events.c.


Function Documentation

int main (  ) 

Definition at line 20 of file PAPI_add_remove_events.c.

00020           {
00021  
00022     int i,retval,tmp;
00023     int EventSet = PAPI_NULL;
00024     /*must be initialized to PAPI_NULL before calling PAPI_create_event*/
00025 
00026     int event_codes[NUM_EVENT]={PAPI_TOT_INS,PAPI_TOT_CYC}; 
00027     char errstring[PAPI_MAX_STR_LEN];
00028     long long values[NUM_EVENT];
00029 
00030    /***************************************************************************
00031    * This part initializes the library and compares the version number of the *
00032    * header file, to the version of the library, if these don't match then it *
00033    * is likely that PAPI won't work correctly.If there is an error, retval    *
00034    * keeps track of the version number.                                       *
00035    ****************************************************************************/
00036 
00037     if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
00038     {
00039         fprintf(stderr, "Error: %s\n", errstring);
00040         exit(1);
00041     }
00042 
00043    
00044     /* Creating event set   */
00045     if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
00046         ERROR_RETURN(retval);
00047 
00048 
00049     /* Add the array of events PAPI_TOT_INS and PAPI_TOT_CYC to the eventset*/
00050     if ((retval=PAPI_add_events(EventSet, event_codes, NUM_EVENT)) != PAPI_OK)
00051         ERROR_RETURN(retval);
00052   
00053        
00054     /* Start counting */
00055     if ( (retval=PAPI_start(EventSet)) != PAPI_OK)
00056         ERROR_RETURN(retval);
00057      
00058     /*** this is where your computation goes *********/
00059     for(i=0;i<1000;i++)
00060     {
00061         tmp = tmp+i;
00062     }  
00063 
00064     /* Stop counting, this reads from the counter as well as stop it. */
00065     if ( (retval=PAPI_stop(EventSet,values)) != PAPI_OK)
00066         ERROR_RETURN(retval);
00067 
00068     printf("\nThe total instructions executed are %lld, total cycles %lld\n",
00069             values[0],values[1]);
00070 
00071     
00072     if ( (retval=PAPI_remove_events(EventSet,event_codes, NUM_EVENT))!=PAPI_OK)
00073         ERROR_RETURN(retval);
00074 
00075     /* Free all memory and data structures, EventSet must be empty. */
00076     if ( (retval=PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
00077         ERROR_RETURN(retval);
00078 
00079     /* free the resources used by PAPI */
00080     PAPI_shutdown();
00081    
00082     exit(0);
00083 }

Here is the call graph for this function:


Generated on 8 Sep 2016 for PAPI by  doxygen 1.6.1