PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
low-level.c File Reference
Include dependency graph for low-level.c:

Go to the source code of this file.

Macros

#define NUM_EVENTS   2
 

Functions

int main (int argc, char **argv)
 

Variables

int TESTS_QUIET
 

Macro Definition Documentation

#define NUM_EVENTS   2

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file low-level.c.

28 {
29  int retval;
30 #define NUM_EVENTS 2
32  int Events[NUM_EVENTS];
33  int EventSet = PAPI_NULL;
34 
35  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
36 
37 
38  if ( ( retval =
40  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
41 
42  /* query and set up the right events to monitor */
43  if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
44  Events[0] = PAPI_FP_INS;
45  Events[1] = PAPI_TOT_CYC;
46  } else {
47  Events[0] = PAPI_TOT_INS;
48  Events[1] = PAPI_TOT_CYC;
49  }
50 
51  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
52  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
53 
54  if ( ( retval =
55  PAPI_add_events( EventSet, ( int * ) Events,
56  NUM_EVENTS ) ) < PAPI_OK )
57  test_fail( __FILE__, __LINE__, "PAPI_add_events", retval );
58 
59  if ( !TESTS_QUIET ) {
60  printf( "\n Incorrect usage of read and accum.\n" );
61  printf( " Some cycles are counted twice\n" );
62  }
63  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
64  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
65 
66  /* Loop 1 */
68 
69  if ( ( retval = PAPI_read( EventSet, values ) ) != PAPI_OK )
70  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
71 
72  if ( !TESTS_QUIET )
73  printf( TWO12, values[0], values[1], "(Counters continuing...)\n" );
74 
75  /* Loop 2 */
77 
78  /* Using PAPI_accum here is incorrect. The result is that Loop 1 *
79  * is being counted twice */
80  if ( ( retval = PAPI_accum( EventSet, values ) ) != PAPI_OK )
81  test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
82 
83  if ( !TESTS_QUIET )
84  printf( TWO12, values[0], values[1], "(Counters being accumulated)\n" );
85 
86  /* Loop 3 */
88 
89  if ( ( retval = PAPI_stop( EventSet, dummyvalues ) ) != PAPI_OK )
90  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
91 
92  if ( ( retval = PAPI_read( EventSet, dummyvalues ) ) != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
94 
95  if ( !TESTS_QUIET ) {
96  printf( TWO12, dummyvalues[0], dummyvalues[1],
97  "(Reading stopped counters)\n" );
98 
99  printf( TWO12, values[0], values[1], "" );
100 
101  printf( "\n Incorrect usage of read and accum.\n" );
102  printf( " Another incorrect use\n" );
103  }
104  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
105  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
106 
107  /* Loop 1 */
108  do_flops( NUM_FLOPS );
109 
110  if ( ( retval = PAPI_read( EventSet, values ) ) != PAPI_OK )
111  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
112 
113  if ( !TESTS_QUIET )
114  printf( TWO12, values[0], values[1], "(Counters continuing...)\n" );
115 
116  /* Loop 2 */
117  /* Code that should not be counted */
118  do_flops( NUM_FLOPS );
119 
120  if ( ( retval = PAPI_read( EventSet, dummyvalues ) ) != PAPI_OK )
121  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
122 
123  if ( !TESTS_QUIET )
124  printf( TWO12, dummyvalues[0], dummyvalues[1],
125  "(Intermediate counts...)\n" );
126 
127  /* Loop 3 */
128  do_flops( NUM_FLOPS );
129 
130  /* Since PAPI_read does not reset the counters it's use above after *
131  * loop 2 is incorrect. Instead Loop1 will in effect be counted twice. *
132  * and the counts in loop 2 are included in the total counts */
133  if ( ( retval = PAPI_accum( EventSet, values ) ) != PAPI_OK )
134  test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
135  if ( !TESTS_QUIET )
136  printf( TWO12, values[0], values[1], "" );
137 
138  if ( ( retval = PAPI_stop( EventSet, dummyvalues ) ) != PAPI_OK )
139  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
140 
141  if ( !TESTS_QUIET ) {
142  printf( "\n Correct usage of read and accum.\n" );
143  printf( " PAPI_reset and PAPI_accum used to skip counting\n" );
144  printf( " a section of the code.\n" );
145  }
146  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
147  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
148 
149  do_flops( NUM_FLOPS );
150 
151  if ( ( retval = PAPI_read( EventSet, values ) ) != PAPI_OK )
152  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
153  if ( !TESTS_QUIET )
154  printf( TWO12, values[0], values[1], "(Counters continuing)\n" );
155 
156  /* Code that should not be counted */
157  do_flops( NUM_FLOPS );
158 
159  if ( ( retval = PAPI_reset( EventSet ) ) != PAPI_OK )
160  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
161 
162  if ( !TESTS_QUIET )
163  printf( "%12s %12s (Counters reset)\n", "", "" );
164 
165  do_flops( NUM_FLOPS );
166 
167  if ( ( retval = PAPI_accum( EventSet, values ) ) != PAPI_OK )
168  test_fail( __FILE__, __LINE__, "PAPI_accum", retval );
169 
170  if ( !TESTS_QUIET )
171  printf( TWO12, values[0], values[1], "" );
172 
173  if ( !TESTS_QUIET ) {
174  printf( "----------------------------------\n" );
175  printf( "Verification: The last line in each experiment should be\n" );
176  printf( "approximately twice the value of the first line.\n" );
177  printf
178  ( "The third case illustrates one possible way to accomplish this.\n" );
179  }
180  test_pass( __FILE__, NULL, 0 );
181  exit( 1 );
182 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define NUM_FLOPS
#define TWO12
Definition: papi_test.h:117
int PAPI_reset(int EventSet)
Definition: papi.c:2377
#define PAPI_NULL
Definition: fpapi.h:13
static int Events[NUM_EVENTS]
Definition: init_fini.c:8
#define PAPI_TOT_INS
Definition: fpapi.h:185
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int PAPI_add_events(int EventSet, int *Events, int number)
Definition: papi.c:5720
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
int PAPI_accum(int EventSet, long long *values)
Definition: papi.c:2662
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
#define PAPI_TOT_CYC
Definition: fpapi.h:194
long long dummyvalues[2]
#define NUM_EVENTS
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_FP_INS
Definition: fpapi.h:187
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:696
int EventSet
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2476
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
void exit()

Here is the call graph for this function:

Variable Documentation

int TESTS_QUIET

Definition at line 11 of file test_utils.c.