PAPI_get_opt.c File Reference

Include dependency graph for PAPI_get_opt.c:

Go to the source code of this file.

Defines

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

Functions

int poorly_tuned_function ()
int main ()

Define Documentation

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

Definition at line 12 of file PAPI_get_opt.c.


Function Documentation

int main (  ) 

Definition at line 26 of file PAPI_get_opt.c.

00027 {
00028 
00029    int num, retval, EventSet = PAPI_NULL;
00030    PAPI_option_t options;    
00031    long long values[2];
00032 
00033    /****************************************************************************
00034    *  This part initializes the library and compares the version number of the *
00035    * header file, to the version of the library, if these don't match then it  *
00036    * is likely that PAPI won't work correctly.If there is an error, retval     *
00037    * keeps track of the version number.                                        *
00038    ****************************************************************************/
00039 
00040    if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
00041    {
00042       printf("Library initialization error! \n");
00043       exit(1);
00044    }
00045 
00046    /*PAPI_get_opt returns a negative number if there is an error */
00047 
00048    /* This call returns the maximum available hardware counters */
00049    if((num = PAPI_get_opt(PAPI_MAX_HWCTRS,NULL)) <= 0)
00050       ERROR_RETURN(num);
00051 
00052 
00053    printf("This machine has %d counters.\n",num);
00054 
00055    if ((retval=PAPI_create_eventset(&EventSet)) != PAPI_OK)
00056       ERROR_RETURN(retval);
00057 
00058    /* Set the domain of this EventSet to counter user and 
00059       kernel modes for this process.                      */
00060         
00061    memset(&options,0x0,sizeof(options));
00062    
00063    options.domain.eventset = EventSet;
00064    /* Default domain is PAPI_DOM_USER */
00065    options.domain.domain = PAPI_DOM_ALL;
00066    /* this sets the options for the domain */
00067    if ((retval=PAPI_set_opt(PAPI_DOMAIN, &options)) != PAPI_OK)
00068       ERROR_RETURN(retval);
00069    /* Add Total Instructions Executed event to the EventSet */
00070    if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_INS)) != PAPI_OK)
00071       ERROR_RETURN(retval);
00072 
00073    /* Add Total Cycles Executed event to the EventSet */
00074    if ( (retval = PAPI_add_event(EventSet, PAPI_TOT_CYC)) != PAPI_OK)
00075       ERROR_RETURN(retval);
00076 
00077    /* Start counting */
00078    if((retval=PAPI_start(EventSet)) != PAPI_OK)
00079       ERROR_RETURN(retval);
00080 
00081    poorly_tuned_function();
00082 
00083    /* Stop counting */
00084    if((retval=PAPI_stop(EventSet, values)) != PAPI_OK)
00085       ERROR_RETURN(retval);
00086 
00087    printf(" Total instructions: %lld   Total Cycles: %lld \n", values[0],
00088             values[1]);
00089    
00090    /* clean up */
00091    PAPI_shutdown();
00092 
00093    exit(0);
00094 }

Here is the call graph for this function:

int poorly_tuned_function (  ) 

Definition at line 14 of file PAPI_get_opt.c.

00015 {
00016    float tmp;
00017    int i;
00018 
00019    for(i=1; i<2000; i++)
00020    {
00021       tmp=(tmp+100)/i;
00022    }
00023    return 0;
00024 }

Here is the caller graph for this function:


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1