high_level.c File Reference

Include dependency graph for high_level.c:

Go to the source code of this file.

Defines

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

Functions

void computation_mult ()
void computation_add ()
int main ()

Define Documentation

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

Definition at line 15 of file high_level.c.

#define NUM_EVENTS   2

Definition at line 13 of file high_level.c.

#define THRESHOLD   10000

Definition at line 14 of file high_level.c.


Function Documentation

void computation_add (  ) 

Definition at line 29 of file high_level.c.

00030 {
00031    int tmp = 0;
00032    int i=0;
00033 
00034    for( i = 0; i < THRESHOLD; i++ )
00035    {
00036       tmp = tmp + i;
00037    }
00038 
00039 }

Here is the caller graph for this function:

void computation_mult (  ) 

Definition at line 18 of file high_level.c.

00019 {
00020    double tmp=1.0;
00021    int i=1;
00022    for( i = 1; i < THRESHOLD; i++ )
00023    {
00024       tmp = tmp*i;
00025    }
00026 }

Here is the caller graph for this function:

int main (  ) 

Definition at line 42 of file high_level.c.

00043 {
00044    /*Declaring and initializing the event set with the presets*/
00045    int Events[2] = {PAPI_TOT_INS, PAPI_TOT_CYC};
00046    /*The length of the events array should be no longer than the 
00047      value returned by PAPI_num_counters.*/ 
00048     
00049    /*declaring place holder for no of hardware counters */
00050    int num_hwcntrs = 0;
00051    int retval;
00052    char errstring[PAPI_MAX_STR_LEN];
00053    /*This is going to store our list of results*/
00054    long long values[NUM_EVENTS];
00055 
00056 
00057    /***************************************************************************
00058    *  This part initializes the library and compares the version number of the*
00059    * header file, to the version of the library, if these don't match then it *
00060    * is likely that PAPI won't work correctly.If there is an error, retval    *
00061    * keeps track of the version number.                                       *
00062    ***************************************************************************/
00063 
00064    if((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT )
00065    {
00066       fprintf(stderr, "Error: %d %s\n",retval, errstring);
00067       exit(1);
00068    }
00069 
00070 
00071    /**************************************************************************
00072     * PAPI_num_counters returns the number of hardware counters the platform *
00073     * has or a negative number if there is an error                          *
00074     **************************************************************************/
00075    if ((num_hwcntrs = PAPI_num_counters()) < PAPI_OK)
00076    {
00077       printf("There are no counters available. \n");
00078       exit(1);
00079    }
00080 
00081    printf("There are %d counters in this system\n",num_hwcntrs);
00082         
00083    /**************************************************************************
00084     * PAPI_start_counters initializes the PAPI library (if necessary) and    *
00085     * starts counting the events named in the events array. This function    *
00086     * implicitly stops and initializes any counters running as a result of   *
00087     * a previous call to PAPI_start_counters.                                *
00088     **************************************************************************/
00089     
00090    if ( (retval = PAPI_start_counters(Events, NUM_EVENTS)) != PAPI_OK)
00091        ERROR_RETURN(retval);
00092 
00093    printf("\nCounter Started: \n");
00094 
00095    /* Your code goes here*/
00096    computation_add();
00097     
00098 
00099   
00100 
00101    /**********************************************************************
00102     * PAPI_read_counters reads the counter values into values array      *
00103     **********************************************************************/
00104 
00105    if ( (retval=PAPI_read_counters(values, NUM_EVENTS)) != PAPI_OK)
00106       ERROR_RETURN(retval);
00107 
00108    printf("Read successfully\n");
00109 
00110 
00111 
00112    printf("The total instructions executed for addition are %lld \n",values[0]);
00113    printf("The total cycles used are %lld \n", values[1] );
00114     
00115    printf("\nNow we try to use PAPI_accum to accumulate values\n"); 
00116 
00117    /* Do some computation here */
00118    computation_add();
00119      
00120  
00121    /************************************************************************
00122     * What PAPI_accum_counters does is it adds the running counter values  *
00123     * to what is in the values array. The hardware counters are reset and  *
00124     * left running after the call.                                         *
00125     ************************************************************************/
00126 
00127    if ( (retval=PAPI_accum_counters(values, NUM_EVENTS)) != PAPI_OK)
00128       ERROR_RETURN(retval);
00129 
00130    printf("We did an additional %d times addition!\n", THRESHOLD);
00131    printf("The total instructions executed for addition are %lld \n",
00132             values[0] );
00133    printf("The total cycles used are %lld \n", values[1] );
00134 
00135    /***********************************************************************
00136     * Stop counting events(this reads the counters as well as stops them  *
00137     ***********************************************************************/
00138 
00139    printf("\nNow we try to do some multiplications\n");
00140    computation_mult();
00141 
00142    /******************* PAPI_stop_counters **********************************/
00143    if ((retval=PAPI_stop_counters(values, NUM_EVENTS)) != PAPI_OK)
00144       ERROR_RETURN(retval); 
00145 
00146    printf("The total instruction executed for multiplication are %lld \n",
00147                values[0] );
00148    printf("The total cycles used are %lld \n", values[1] );
00149    exit(0); 
00150 }

Here is the call graph for this function:


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1