PAPI 7.1.0.0
Loading...
Searching...
No Matches
Simple_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
8long long int low_mark[10] = { 0LL, 2LL, 2LL, 7LL, 21LL, 29LL, 29LL, 29LL, 29LL, 34LL};
9long long int high_mark[10] = { 1LL, 1LL, 2LL, 3LL, 4LL, 8LL, 9LL, 9LL, 9LL, 13LL};
10long long int tot_iter[10] = { 2LL, 9LL, 13LL, 33LL, 83LL, 122LL, 126LL, 130LL, 135LL, 176LL};
11double comp_val[10] = {0.653676, 3.160483, 4.400648, 10.286250, 25.162759, 36.454895, 37.965891, 39.680220, 41.709039, 53.453990};
12
13void setup_PAPI(int *event_set);
14void simple_init(void);
15double simple_compute(double x);
16
17int main(int argc, char **argv){
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}
76
77
78void setup_PAPI(int *event_set){
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}
107
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
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
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_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
volatile double x