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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file papi_br_ntk.c.

18 {
19
20 int num_runs=100,i;
21 long long high=0,low=0,average=0,expected=500000;
22 double error;
23
24 long long count,total=0;
25 int quiet=0,retval,ins_result;
26 int eventset=PAPI_NULL;
27
28 quiet=tests_quiet(argc,argv);
29
30 if (!quiet) {
31 printf("\nTesting the PAPI_BR_NTK event.\n");
32 }
33
34 /* Init the PAPI library */
36 if ( retval != PAPI_VER_CURRENT ) {
37 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
38 }
39
41 if (retval!=PAPI_OK) {
42 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
43 }
44
45 retval=PAPI_add_named_event(eventset,"PAPI_BR_NTK");
46 if (retval!=PAPI_OK) {
47 test_skip( __FILE__, __LINE__, "adding PAPI_BR_NTK", retval );
48 }
49
50 if (!quiet) {
51 printf("Testing a loop with %lld branches (%d times):\n",
52 expected,num_runs);
53 }
54
55 for(i=0;i<num_runs;i++) {
56 PAPI_reset(eventset);
57 PAPI_start(eventset);
58
59 ins_result=branches_testcode();
60
61 retval=PAPI_stop(eventset,&count);
62
63 if (ins_result==CODE_UNIMPLEMENTED) {
64 fprintf(stderr,"\tCode unimplemented\n");
65 test_skip( __FILE__, __LINE__, "unimplemented", 0);
66 }
67
68 if (retval!=PAPI_OK) {
69 test_fail( __FILE__, __LINE__,
70 "reading PAPI_TOT_INS", retval );
71 }
72
73 if (count>high) high=count;
74 if ((low==0) || (count<low)) low=count;
75 total+=count;
76 }
77
78 average=(total/num_runs);
79
80 error=display_error(average,high,low,expected,quiet);
81
82 if ((error > 1.0) || (error<-1.0)) {
83 if (!quiet) printf("Instruction count off by more than 1%%\n");
84 test_fail( __FILE__, __LINE__, "Error too high", 1 );
85 }
86
87 if (!quiet) printf("\n");
88
89 test_pass( __FILE__ );
90
92
93 return 0;
94}
int i
int branches_testcode(void)
static long count
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
FILE * stderr
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
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
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
static int total
Definition: rapl_overflow.c:9
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: