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

Go to the source code of this file.

Functions

void simple_init (void)
 
double simple_compute (double x)
 
long long int counter_accessor_function (void *param)
 
papi_handle_t papi_sde_hook_list_events (papi_sde_fptr_struct_t *fptr_struct)
 

Variables

static double comp_value
 
static long long int total_iter_cnt
 
static long long int low_wtrmrk
 
static long long int high_wtrmrk
 
static papi_handle_t handle
 
static const char * ev_names [4]
 

Function Documentation

◆ counter_accessor_function()

long long counter_accessor_function ( void *  param)

Definition at line 69 of file Simple2_Lib.c.

69 {
70 long long ll;
71 double *dbl_ptr = (double *)param;
72
73 // Scale the variable by a factor of two. Real libraries will do meaningful work here.
74 double value = *dbl_ptr * 2.0;
75
76 // Copy the bits of the result in a long long int.
77 (void)memcpy(&ll, &value, sizeof(double));
78
79 return ll;
80}
Here is the caller graph for this function:

◆ papi_sde_hook_list_events()

papi_handle_t papi_sde_hook_list_events ( papi_sde_fptr_struct_t fptr_struct)

Definition at line 50 of file Simple2_Lib.c.

50 {
51 handle = fptr_struct->init("Simple2");
56 fptr_struct->add_counter_to_group(handle, ev_names[2], "ANY_WATERMARK_REACHED", PAPI_SDE_SUM);
57 fptr_struct->add_counter_to_group(handle, ev_names[3], "ANY_WATERMARK_REACHED", PAPI_SDE_SUM);
58
59 fptr_struct->describe_counter(handle, ev_names[0], "Sum of values that are within the watermarks.");
60 fptr_struct->describe_counter(handle, ev_names[1], "Total iterations executed by the library.");
61 fptr_struct->describe_counter(handle, ev_names[2], "Number of times a value was below the low watermark.");
62 fptr_struct->describe_counter(handle, ev_names[3], "Number of times a value was above the high watermark.");
63 fptr_struct->describe_counter(handle, "ANY_WATERMARK_REACHED", "Number of times a value was not between the two watermarks.");
64
65 return handle;
66}
static const char * ev_names[4]
Definition: Simple2_Lib.c:18
long long int counter_accessor_function(void *param)
Definition: Simple2_Lib.c:69
static long long int total_iter_cnt
Definition: Simple2_Lib.c:15
static long long int high_wtrmrk
Definition: Simple2_Lib.c:15
static papi_handle_t handle
Definition: Simple2_Lib.c:16
static long long int low_wtrmrk
Definition: Simple2_Lib.c:15
static double comp_value
Definition: Simple2_Lib.c:14
#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_SUM
Definition: sde_lib.h:33
#define PAPI_SDE_DELTA
Definition: sde_lib.h:25
int(* describe_counter)(papi_handle_t handle, const char *event_name, const char *event_description)
Definition: sde_lib.h:108
papi_handle_t(* init)(const char *lib_name)
Definition: sde_lib.h:103
int(* register_counter)(papi_handle_t handle, const char *event_name, int mode, int type, void *counter)
Definition: sde_lib.h:105
int(* add_counter_to_group)(papi_handle_t handle, const char *event_name, const char *group_name, uint32_t group_flags)
Definition: sde_lib.h:109
int(* register_counter_cb)(papi_handle_t handle, const char *event_name, int mode, int type, papi_sde_fptr_t callback, void *param)
Definition: sde_lib.h:106
Here is the call graph for this function:

◆ simple_compute()

double simple_compute ( double  x)

Definition at line 84 of file Simple2_Lib.c.

84 {
85 double sum = 0.0;
86 int lcl_iter = 0;
87
88 if( x > 1.0 )
89 x = 1.0/x;
90 if( x < 0.000001 )
91 x += 0.3579;
92
93 while( 1 ){
94 double y,x2,x3,x4;
95 lcl_iter++;
96
97 // Compute a function with range [0:1] so we can iterate
98 // multiple times without diverging or creating FP exceptions.
99 x2 = x*x;
100 x3 = x2*x;
101 x4 = x2*x2;
102 y = 42.53*x4 -67.0*x3 +25.0*x2 +x/2.15;
103 y = y*y;
104 if( y < 0.01 )
105 y = 0.5-y;
106
107 // Now set the next x to be the current y, so we can iterate again.
108 x = y;
109
110 // Add y to sum unconditionally
111 sum += y;
112
113 if( y < 0.1 ){
114 low_wtrmrk++;
115 continue;
116 }
117
118 if( y > 0.9 ){
119 high_wtrmrk++;
120 continue;
121 }
122
123 // Only add y to comp_value if y is between the low and high watermarks.
124 comp_value += y;
125
126 // If some condition is met, terminate the loop
127 if( 0.61 < y && y < 0.69 )
128 break;
129 }
130 total_iter_cnt += lcl_iter;
131
132 return sum;
133}
volatile double y
volatile double x
Here is the caller graph for this function:

◆ simple_init()

void simple_init ( void  )

Definition at line 27 of file Simple2_Lib.c.

27 {
28
29 // Initialize library specific variables
30 comp_value = 0.0;
32 low_wtrmrk = 0;
33 high_wtrmrk = 0;
34
35 // Initialize PAPI SDEs
36 handle = papi_sde_init("Simple2");
41 papi_sde_add_counter_to_group(handle, ev_names[2], "ANY_WATERMARK_REACHED", PAPI_SDE_SUM);
42 papi_sde_add_counter_to_group(handle, ev_names[3], "ANY_WATERMARK_REACHED", PAPI_SDE_SUM);
43
44 return;
45}
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
int papi_sde_add_counter_to_group(papi_handle_t handle, const char *event_name, const char *group_name, uint32_t group_flags)
Definition: sde_lib.c:449
int papi_sde_register_counter_cb(papi_handle_t handle, const char *event_name, int cntr_mode, int cntr_type, papi_sde_fptr_t callback, void *param)
Definition: sde_lib.c:312
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ comp_value

double comp_value
static

Definition at line 14 of file Simple2_Lib.c.

◆ ev_names

const char* ev_names[4]
static
Initial value:
= {
"COMPUTED_VALUE",
"TOTAL_ITERATIONS",
"LOW_WATERMARK_REACHED",
"HIGH_WATERMARK_REACHED"
}

Definition at line 18 of file Simple2_Lib.c.

◆ handle

papi_handle_t handle
static

Definition at line 16 of file Simple2_Lib.c.

◆ high_wtrmrk

long long int high_wtrmrk
static

Definition at line 15 of file Simple2_Lib.c.

◆ low_wtrmrk

long long int low_wtrmrk
static

Definition at line 15 of file Simple2_Lib.c.

◆ total_iter_cnt

long long int total_iter_cnt
static

Definition at line 15 of file Simple2_Lib.c.