PAPI 7.1.0.0
Loading...
Searching...
No Matches
Simple_Driver.c File Reference
Include dependency graph for Simple_Driver.c:

Go to the source code of this file.

Functions

void setup_PAPI (int *event_set)
 
void simple_init (void)
 
double simple_compute (double x)
 
int main (int argc, char **argv)
 

Variables

long long int low_mark [10] = { 0LL, 2LL, 2LL, 7LL, 21LL, 29LL, 29LL, 29LL, 29LL, 34LL}
 
long long int high_mark [10] = { 1LL, 1LL, 2LL, 3LL, 4LL, 8LL, 9LL, 9LL, 9LL, 13LL}
 
long long int tot_iter [10] = { 2LL, 9LL, 13LL, 33LL, 83LL, 122LL, 126LL, 130LL, 135LL, 176LL}
 
double comp_val [10] = {0.653676, 3.160483, 4.400648, 10.286250, 25.162759, 36.454895, 37.965891, 39.680220, 41.709039, 53.453990}
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 17 of file Simple_Driver.c.

17 {
18 int i,ret, event_set = PAPI_NULL;
19 int discrepancies = 0;
20 int be_verbose = 0;
21 long long counter_values[4];
22 double *dbl_ptr;
23
24 if( (argc > 1) && !strcmp(argv[1], "-verbose") )
25 be_verbose = 1;
26
28
29 setup_PAPI(&event_set);
30
31 // --- Start PAPI
32 if((ret=PAPI_start(event_set)) != PAPI_OK){
33 test_fail( __FILE__, __LINE__, "PAPI_start", ret );
34 }
35
36 for(i=0; i<10; i++){
37 double sum;
38
39 sum = simple_compute(0.87*i);
40 if( be_verbose ) printf("sum=%lf\n",sum);
41
42 // --- read the event counters
43 if((ret=PAPI_read(event_set, counter_values)) != PAPI_OK){
44 test_fail( __FILE__, __LINE__, "PAPI_read", ret );
45 }
46
47 // PAPI has packed the bits of the double inside the long long.
48 dbl_ptr = (double *)&counter_values[3];
49 if( be_verbose ) printf("Low Mark=%lld, High Mark=%lld, Total Iterations=%lld, Comp. Value=%lf\n",
50 counter_values[0], counter_values[1], counter_values[2], *dbl_ptr);
51
52 if( counter_values[0] != low_mark[i] ||
53 counter_values[1] != high_mark[i] ||
54 counter_values[2] != tot_iter[i] ||
55 (*dbl_ptr-comp_val[i]) > 0.00001 ||
56 (*dbl_ptr-comp_val[i]) < -0.00001 ){
57 discrepancies++;
58 }
59
60 }
61
62 // --- Stop PAPI
63 if((ret=PAPI_stop(event_set, counter_values)) != PAPI_OK){
64 test_fail( __FILE__, __LINE__, "PAPI_stop", ret );
65 }
66
67 if( !discrepancies )
68 test_pass(__FILE__);
69 else
70 test_fail( __FILE__, __LINE__, "SDE counter values are wrong!", 0 );
71
72 // The following "return" is dead code, because both test_pass() and test_fail() call exit(),
73 // however, we need it to prevent compiler warnings.
74 return 0;
75}
int be_verbose
int i
long long int high_mark[10]
Definition: Simple_Driver.c:9
void setup_PAPI(int *event_set)
Definition: Simple_Driver.c:78
void simple_init(void)
Definition: Simple_Lib.c:25
double simple_compute(double x)
Definition: Simple_Lib.c:45
long long int low_mark[10]
Definition: Simple_Driver.c:8
long long int tot_iter[10]
Definition: Simple_Driver.c:10
double comp_val[10]
Definition: Simple_Driver.c:11
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
Here is the call graph for this function:

◆ setup_PAPI()

void setup_PAPI ( int event_set)

Definition at line 78 of file Simple_Driver.c.

78 {
79 int ret;
80
82 test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
83 }
84
85 if((ret=PAPI_create_eventset(event_set)) != PAPI_OK){
86 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
87 }
88
89 if((ret=PAPI_add_named_event(*event_set, "sde:::Simple::LOW_WATERMARK_REACHED")) != PAPI_OK){
90 test_fail( __FILE__, __LINE__, "PAPI_add_named_event", ret );
91 }
92
93 if((ret=PAPI_add_named_event(*event_set, "sde:::Simple::HIGH_WATERMARK_REACHED")) != PAPI_OK){
94 test_fail( __FILE__, __LINE__, "PAPI_add_named_event", ret );
95 }
96
97 if((ret=PAPI_add_named_event(*event_set, "sde:::Simple::TOTAL_ITERATIONS")) != PAPI_OK){
98 test_fail( __FILE__, __LINE__, "PAPI_add_named_event", ret );
99 }
100
101 if((ret=PAPI_add_named_event(*event_set, "sde:::Simple::COMPUTED_VALUE")) != PAPI_OK){
102 test_fail( __FILE__, __LINE__, "PAPI_add_named_event", ret );
103 }
104
105 return;
106}
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ simple_compute()

double simple_compute ( double  x)

Definition at line 45 of file Simple_Lib.c.

45 {
46 double sum = 0.0;
47 int lcl_iter = 0;
48
49 if( x > 1.0 )
50 x = 1.0/x;
51 if( x < 0.000001 )
52 x += 0.3579;
53
54 while( 1 ){
55 double y,x2,x3,x4;
56 lcl_iter++;
57
58 // Compute a function with range [0:1] so we can iterate
59 // multiple times without diverging or creating FP exceptions.
60 x2 = x*x;
61 x3 = x2*x;
62 x4 = x2*x2;
63 y = 42.53*x4 -67.0*x3 +25.0*x2 +x/2.15;
64 y = y*y;
65 if( y < 0.01 )
66 y = 0.5-y;
67
68 // Now set the next x to be the current y, so we can iterate again.
69 x = y;
70
71 // Add y to sum unconditionally
72 sum += y;
73
74 if( y < 0.1 ){
75 low_wtrmrk++;
76 continue;
77 }
78
79 if( y > 0.9 ){
81 continue;
82 }
83
84 // Only add y to comp_value if y is between the low and high watermarks.
85 comp_value += y;
86
87 // If some condition is met, terminate the loop
88 if( 0.61 < y && y < 0.69 )
89 break;
90 }
91 total_iter_cnt += lcl_iter;
92
93 return sum;
94}
static long long int total_iter_cnt
Definition: Simple_Lib.c:14
static long long int high_wtrmrk
Definition: Simple_Lib.c:14
static long long int low_wtrmrk
Definition: Simple_Lib.c:14
static double comp_value
Definition: Simple_Lib.c:13
volatile double y
volatile double x
Here is the caller graph for this function:

◆ simple_init()

void simple_init ( void  )

Definition at line 25 of file Simple_Lib.c.

25 {
26
27 // Initialize library specific variables
28 comp_value = 0.0;
30 low_wtrmrk = 0;
31 high_wtrmrk = 0;
32
33 // Initialize PAPI SDEs
34 handle = papi_sde_init("Simple");
39
40 return;
41}
static const char * ev_names[4]
Definition: Simple_Lib.c:17
static papi_handle_t handle
Definition: Simple_Lib.c:15
papi_handle_t papi_sde_init(const char *name_of_library)
Definition: sde_lib.c:119
int papi_sde_register_counter(papi_handle_t handle, const char *event_name, int cntr_mode, int cntr_type, void *counter)
Definition: sde_lib.c:276
#define PAPI_SDE_double
Definition: sde_lib.h:30
#define PAPI_SDE_long_long
Definition: sde_lib.h:28
#define PAPI_SDE_RO
Definition: sde_lib.h:23
#define PAPI_SDE_INSTANT
Definition: sde_lib.h:26
#define PAPI_SDE_DELTA
Definition: sde_lib.h:25
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ comp_val

double comp_val[10] = {0.653676, 3.160483, 4.400648, 10.286250, 25.162759, 36.454895, 37.965891, 39.680220, 41.709039, 53.453990}

Definition at line 11 of file Simple_Driver.c.

◆ high_mark

long long int high_mark[10] = { 1LL, 1LL, 2LL, 3LL, 4LL, 8LL, 9LL, 9LL, 9LL, 13LL}

Definition at line 9 of file Simple_Driver.c.

◆ low_mark

long long int low_mark[10] = { 0LL, 2LL, 2LL, 7LL, 21LL, 29LL, 29LL, 29LL, 29LL, 34LL}

Definition at line 8 of file Simple_Driver.c.

◆ tot_iter

long long int tot_iter[10] = { 2LL, 9LL, 13LL, 33LL, 83LL, 122LL, 126LL, 130LL, 135LL, 176LL}

Definition at line 10 of file Simple_Driver.c.