PAPI 7.1.0.0
Loading...
Searching...
No Matches
Created_Counter_Driver.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <string.h>
5#include "papi.h"
6#include "papi_test.h"
7
8void cclib_init(void);
9void cclib_do_work(void);
10void cclib_do_more_work(void);
11void setup_PAPI(int *event_set);
12
13long long int epsilon_v[10] = {14LL, 11LL, 8LL, 13LL, 8LL, 10LL, 12LL, 11LL, 6LL, 8LL};
14int be_verbose = 0;
15
16int main(int argc, char **argv){
17 int i, ret, event_set = PAPI_NULL;
18 int discrepancies = 0;
19 long long counter_values[1] = {0};
20
21 if( (argc > 1) && !strcmp(argv[1], "-verbose") )
22 be_verbose = 1;
23
24 cclib_init();
25
26 setup_PAPI(&event_set);
27
28 // --- Start PAPI
29 if((ret=PAPI_start(event_set)) != PAPI_OK){
30 test_fail( __FILE__, __LINE__, "PAPI_start", ret );
31 }
32
33 for(i=0; i<10; i++){
34
36
37 // --- Read the event counters _and_ reset them
38 if((ret=PAPI_accum(event_set, counter_values)) != PAPI_OK){
39 test_fail( __FILE__, __LINE__, "PAPI_accum", ret );
40 }
41 if( be_verbose ) printf("Epsilon count in cclib_do_work(): %lld\n",counter_values[0]);
42 if( counter_values[0] != epsilon_v[i] ){
43 discrepancies++;
44 }
45 counter_values[0] = 0;
46
47 }
48
49 // --- Stop PAPI
50 if((ret=PAPI_stop(event_set, counter_values)) != PAPI_OK){
51 test_fail( __FILE__, __LINE__, "PAPI_stop", ret );
52 }
53
54 if( !discrepancies )
55 test_pass(__FILE__);
56 else
57 test_fail( __FILE__, __LINE__, "SDE counter values are wrong!", 0 );
58
59 // The following "return" is dead code, because both test_pass() and test_fail() call exit(),
60 // however, we need it to prevent compiler warnings.
61 return 0;
62}
63
64
65void setup_PAPI(int *event_set){
66 int ret;
67
69 test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
70 }
71
72 if((ret=PAPI_create_eventset(event_set)) != PAPI_OK){
73 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
74 }
75
76 if((ret=PAPI_add_named_event(*event_set, "sde:::Lib_With_CC::epsilon_count")) != PAPI_OK){
77 test_fail( __FILE__, __LINE__, "PAPI_add_named_event", ret );
78 }
79
80 return;
81}
82
void setup_PAPI(int *event_set)
int be_verbose
void cclib_init(void)
long long int epsilon_v[10]
void cclib_do_work(void)
void cclib_do_more_work(void)
int i
Accumulate and reset counters in an EventSet.
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
Return codes and api definitions.
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
int main()
Definition: pernode.c:20