|
PAPI
5.0.1.0
|

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 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.
| void computation_add | ( | ) |
| void computation_mult | ( | ) |
| int main | ( | ) |
Definition at line 42 of file high_level.c.
{
/*Declaring and initializing the event set with the presets*/
int Events[2] = {PAPI_TOT_INS, PAPI_TOT_CYC};
/*The length of the events array should be no longer than the
value returned by PAPI_num_counters.*/
/*declaring place holder for no of hardware counters */
int num_hwcntrs = 0;
int retval;
char errstring[PAPI_MAX_STR_LEN];
/*This is going to store our list of results*/
long long values[NUM_EVENTS];
/***************************************************************************
* 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: %d %s\n",retval, errstring);
exit(1);
}
/**************************************************************************
* PAPI_num_counters returns the number of hardware counters the platform *
* has or a negative number if there is an error *
**************************************************************************/
if ((num_hwcntrs = PAPI_num_counters()) < PAPI_OK)
{
printf("There are no counters available. \n");
exit(1);
}
printf("There are %d counters in this system\n",num_hwcntrs);
/**************************************************************************
* PAPI_start_counters initializes the PAPI library (if necessary) and *
* starts counting the events named in the events array. This function *
* implicitly stops and initializes any counters running as a result of *
* a previous call to PAPI_start_counters. *
**************************************************************************/
if ( (retval = PAPI_start_counters(Events, NUM_EVENTS)) != PAPI_OK)
ERROR_RETURN(retval);
printf("\nCounter Started: \n");
/* Your code goes here*/
computation_add();
/**********************************************************************
* PAPI_read_counters reads the counter values into values array *
**********************************************************************/
if ( (retval=PAPI_read_counters(values, NUM_EVENTS)) != PAPI_OK)
ERROR_RETURN(retval);
printf("Read successfully\n");
printf("The total instructions executed for addition are %lld \n",values[0]);
printf("The total cycles used are %lld \n", values[1] );
printf("\nNow we try to use PAPI_accum to accumulate values\n");
/* Do some computation here */
computation_add();
/************************************************************************
* What PAPI_accum_counters does is it adds the running counter values *
* to what is in the values array. The hardware counters are reset and *
* left running after the call. *
************************************************************************/
if ( (retval=PAPI_accum_counters(values, NUM_EVENTS)) != PAPI_OK)
ERROR_RETURN(retval);
printf("We did an additional %d times addition!\n", THRESHOLD);
printf("The total instructions executed for addition are %lld \n",
values[0] );
printf("The total cycles used are %lld \n", values[1] );
/***********************************************************************
* Stop counting events(this reads the counters as well as stops them *
***********************************************************************/
printf("\nNow we try to do some multiplications\n");
computation_mult();
/******************* PAPI_stop_counters **********************************/
if ((retval=PAPI_stop_counters(values, NUM_EVENTS)) != PAPI_OK)
ERROR_RETURN(retval);
printf("The total instruction executed for multiplication are %lld \n",
values[0] );
printf("The total cycles used are %lld \n", values[1] );
exit(0);
}
