PAPI  5.0.1.0
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.

          {
 
    int i,retval,tmp;
    int EventSet = PAPI_NULL;
    /*must be initialized to PAPI_NULL before calling PAPI_create_event*/

    int event_codes[NUM_EVENT]={PAPI_TOT_INS,PAPI_TOT_CYC}; 
    char errstring[PAPI_MAX_STR_LEN];
    long long values[NUM_EVENT];

   /***************************************************************************
   * This part initializes the library and compares the version number of the *
   * header file, to the version of the library, if these don't match then it *
   * is likely that PAPI won't work correctly.If there is an error, retval    *
   * keeps track of the version number.                                       *
   ****************************************************************************/

    if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
    {
        fprintf(stderr, "Error: %s\n", errstring);
        exit(1);
    }

   
    /* Creating event set   */
    if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
        ERROR_RETURN(retval);


    /* Add the array of events PAPI_TOT_INS and PAPI_TOT_CYC to the eventset*/
    if ((retval=PAPI_add_events(EventSet, event_codes, NUM_EVENT)) != PAPI_OK)
        ERROR_RETURN(retval);
  
       
    /* Start counting */
    if ( (retval=PAPI_start(EventSet)) != PAPI_OK)
        ERROR_RETURN(retval);
     
    /*** this is where your computation goes *********/
    for(i=0;i<1000;i++)
    {
        tmp = tmp+i;
    }  

    /* Stop counting, this reads from the counter as well as stop it. */
    if ( (retval=PAPI_stop(EventSet,values)) != PAPI_OK)
        ERROR_RETURN(retval);

    printf("\nThe total instructions executed are %lld, total cycles %lld\n",
            values[0],values[1]);

    
    if ( (retval=PAPI_remove_events(EventSet,event_codes, NUM_EVENT))!=PAPI_OK)
        ERROR_RETURN(retval);

    /* Free all memory and data structures, EventSet must be empty. */
    if ( (retval=PAPI_destroy_eventset(&EventSet)) != PAPI_OK)
        ERROR_RETURN(retval);

    /* free the resources used by PAPI */
    PAPI_shutdown();
   
    exit(0);
}

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines