PAPI 7.1.0.0
Loading...
Searching...
No Matches
Lib_With_Created_Counter.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdint.h>
3#include <limits.h>
4#include <unistd.h>
5#include "sde_lib.h"
6
7#define MY_EPSILON 0.0001
8
9#define BRNG() {\
10 b = ((z1 << 6) ^ z1) >> 13;\
11 z1 = ((z1 & 4294967294U) << 18) ^ b;\
12 b = ((z2 << 2) ^ z2) >> 27;\
13 z2 = ((z2 & 4294967288U) << 2) ^ b;\
14 b = ((z3 << 13) ^ z3) >> 21;\
15 z3 = ((z3 & 4294967280U) << 7) ^ b;\
16 b = ((z4 << 3) ^ z4) >> 12;\
17 z4 = ((z4 & 4294967168U) << 13) ^ b;\
18 z1++;\
19 result = z1 ^ z2 ^ z3 ^ z4;\
20}
21volatile int result;
22volatile unsigned int b, z1, z2, z3, z4;
23
24static const char *event_names[1] = {
25 "epsilon_count"
26};
27
29
30// API functions.
31void cclib_init(void);
32void cclib_do_work(void);
33void cclib_do_more_work(void);
34
35void cclib_init(void){
36 papi_handle_t sde_handle;
37
38 sde_handle = papi_sde_init("Lib_With_CC");
40
41 z1=42;
42 z2=420;
43 z3=42000;
44 z4=424242;
45
46 return;
47}
48
49void cclib_do_work(void){
50 int i;
51
52 for(i=0; i<100*1000; i++){
53 BRNG();
54 double r = (1.0*result)/(1.0*INT_MAX);
55 if( r < MY_EPSILON && r > -MY_EPSILON ){
57 }
58 // Do some usefull work here
59 if( !(i%100) )
60 (void)usleep(1);
61 }
62
63 return;
64}
65
67 int i;
68
69 for(i=0; i<500*1000; i++){
70 BRNG();
71 double r = (1.0*result)/(1.0*INT_MAX);
72 if( r < MY_EPSILON && r > -MY_EPSILON ){
74 }
75 // Do some usefull work here
76 if( !(i%20) )
77 (void)usleep(1);
78 }
79
80 return;
81}
82
83// Hook for papi_native_avail utility. No user code which links against this library should call
84// this function because it has the same name in all SDE-enabled libraries. papi_native_avail
85// uses dlopen and dlclose on each library so it only has one version of this symbol at a time.
87 papi_handle_t sde_handle;
88 sde_handle = fptr_struct->init("Lib_With_CC");
89 fptr_struct->create_counter(sde_handle, event_names[0], PAPI_SDE_DELTA, &cntr_handle);
90 fptr_struct->describe_counter(sde_handle, event_names[0], "Number of times the random value was less than 0.0001");
91 return sde_handle;
92}
#define MY_EPSILON
void * cntr_handle
#define BRNG()
volatile int result
papi_handle_t papi_sde_hook_list_events(papi_sde_fptr_struct_t *fptr_struct)
void cclib_init(void)
volatile unsigned int z1
static const char * event_names[1]
void cclib_do_work(void)
volatile unsigned int b
volatile unsigned int z2
volatile unsigned int z3
volatile unsigned int z4
void cclib_do_more_work(void)
int i
papi_handle_t papi_sde_init(const char *name_of_library)
Definition: sde_lib.c:119
int papi_sde_inc_counter(papi_handle_t cntr_handle, long long int increment)
Definition: sde_lib.c:637
int papi_sde_create_counter(papi_handle_t handle, const char *event_name, int cntr_mode, void **cntr_handle)
Definition: sde_lib.c:576
SDE prototypes and macros.
void * papi_handle_t
Definition: sde_lib.h:100
#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(* create_counter)(papi_handle_t handle, const char *event_name, int cntr_type, void **cntr_handle)
Definition: sde_lib.h:110