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

Go to the source code of this file.

Functions

void simple_init (void)
 
double simple_compute (double x)
 

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

◆ 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

◆ 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

Variable Documentation

◆ comp_value

double comp_value
static

Definition at line 13 of file Simple_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 17 of file Simple_Lib.c.

◆ handle

papi_handle_t handle
static

Definition at line 15 of file Simple_Lib.c.

◆ high_wtrmrk

long long int high_wtrmrk
static

Definition at line 14 of file Simple_Lib.c.

◆ low_wtrmrk

long long int low_wtrmrk
static

Definition at line 14 of file Simple_Lib.c.

◆ total_iter_cnt

long long int total_iter_cnt
static

Definition at line 14 of file Simple_Lib.c.