PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
first.c File Reference
Include dependency graph for first.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

int TESTS_QUIET
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 27 of file first.c.

28 {
29  int retval, num_tests = 5, num_events, tmp;
30  long long **values;
31  int EventSet = PAPI_NULL;
32  int PAPI_event, mask;
33  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
34  long long min, max;
35 
36  /* Set TESTS_QUIET variable */
37  tests_quiet( argc, argv );
38 
39  /* Init PAPI library */
41  if ( retval != PAPI_VER_CURRENT ) {
42  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43  }
44 
45  /* add PAPI_TOT_CYC and one of the events in
46  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
47  depending on the availability of the event
48  on the platform */
49  EventSet = add_two_events( &num_events, &PAPI_event, &mask );
50 
51  retval = PAPI_event_code_to_name( PAPI_event, event_name );
52  if ( retval != PAPI_OK ) {
53  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
54  }
55  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
56 
57  /* Allocate space for results */
58  values = allocate_test_space( num_tests, num_events );
59 
60  /* Start PAPI */
61  retval = PAPI_start( EventSet );
62  if ( retval != PAPI_OK ) {
63  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
64  }
65 
66  /* Benchmark code */
68 
69  /* read results 0 */
70  retval = PAPI_read( EventSet, values[0] );
71  if ( retval != PAPI_OK ) {
72  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
73  }
74 
75  /* Reset */
76  retval = PAPI_reset( EventSet );
77  if ( retval != PAPI_OK ) {
78  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
79  }
80 
81  /* Benchmark some more */
83 
84  /* Read Results 1 */
85  retval = PAPI_read( EventSet, values[1] );
86  if ( retval != PAPI_OK ) {
87  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
88  }
89 
90  /* Benchmark some more */
92 
93  /* Read results 2 */
94  retval = PAPI_read( EventSet, values[2] );
95  if ( retval != PAPI_OK ) {
96  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
97  }
98 
99  /* Benchmark some more */
100  do_flops( NUM_FLOPS );
101 
102  /* Read results 3 */
103  retval = PAPI_stop( EventSet, values[3] );
104  if ( retval != PAPI_OK ) {
105  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
106  }
107 
108  /* Read results 4 */
109  retval = PAPI_read( EventSet, values[4] );
110  if ( retval != PAPI_OK ) {
111  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
112  }
113 
114  /* remove results. We never stop??? */
115  remove_test_events( &EventSet, mask );
116 
117  if ( !TESTS_QUIET ) {
118  printf( "Test case 1: Non-overlapping start, stop, read.\n" );
119  printf( "-----------------------------------------------\n" );
120  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
121  printf( "Default domain is: %d (%s)\n", tmp,
122  stringify_all_domains( tmp ) );
123  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
124  printf( "Default granularity is: %d (%s)\n", tmp,
125  stringify_granularity( tmp ) );
126  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
127  printf( "-------------------------------------------------------------------------\n" );
128 
129  printf( "Test type : 1 2 3 4 5\n" );
130  sprintf( add_event_str, "%s:", event_name );
131  printf( TAB5, add_event_str,
132  values[0][1], values[1][1], values[2][1],
133  values[3][1], values[4][1] );
134  printf( TAB5, "PAPI_TOT_CYC:",
135  values[0][0], values[1][0], values[2][0],
136  values[3][0], values[4][0] );
137  printf( "-------------------------------------------------------------------------\n" );
138 
139  printf( "Verification:\n" );
140  printf( "Row 1 Column 1 at least %d\n", NUM_FLOPS );
141  printf( "%% difference between %s 1 & 2: %.2f\n", add_event_str,
142  100.0 * ( float ) values[0][1] /
143  ( float ) values[1][1] );
144  printf( "%% difference between %s 1 & 2: %.2f\n", "PAPI_TOT_CYC",
145  100.0 * ( float ) values[0][0] /
146  ( float ) values[1][0] );
147  printf( "Column 1 approximately equals column 2\n" );
148  printf( "Column 3 approximately equals 2 * column 2\n" );
149  printf( "Column 4 approximately equals 3 * column 2\n" );
150  printf( "Column 4 exactly equals column 5\n" );
151  }
152 
153  /* Validation */
154 
155  /* Check cycles constraints */
156 
157  min = ( long long ) ( ( double ) values[1][0] * .8 );
158  max = ( long long ) ( ( double ) values[1][0] * 1.2 );
159 
160  /* Check constraint Col1=Col2 */
161  if ( values[0][0] > max || values[0][0] < min ) {
162  test_fail( __FILE__, __LINE__, "Cycle Col1!=Col2", 1 );
163  }
164  /* Check constraint col3 == 2*col2 */
165  if ( (values[2][0] > ( 2 * max )) ||
166  (values[2][0] < ( 2 * min )) ) {
167  test_fail( __FILE__, __LINE__, "Cycle Col3!=2*Col2", 1 );
168  }
169  /* Check constraint col4 == 3*col2 */
170  if ( (values[3][0] > ( 3 * max )) ||
171  (values[3][0] < ( 3 * min )) ) {
172  test_fail( __FILE__, __LINE__, "Cycle Col3!=3*Col2", 1 );
173  }
174  /* Check constraint col4 == col5 */
175  if ( values[3][0] != values[4][0] ) {
176  test_fail( __FILE__, __LINE__, "Cycle Col4!=Col5", 1 );
177  }
178 
179 
180  /* Check FLOP constraints */
181 
182  min = ( long long ) ( ( double ) values[1][1] * .9 );
183  max = ( long long ) ( ( double ) values[1][1] * 1.1 );
184 
185  /* Check constraint Col1=Col2 */
186  if ( values[0][1] > max || values[0][1] < min ) {
187  test_fail( __FILE__, __LINE__, "FLOP Col1!=Col2", 1 );
188  }
189  /* Check constraint col3 == 2*col2 */
190  if ( (values[2][1] > ( 2 * max )) ||
191  (values[2][1] < ( 2 * min )) ) {
192  test_fail( __FILE__, __LINE__, "FLOP Col3!=2*Col2", 1 );
193  }
194  /* Check constraint col4 == 3*col2 */
195  if ( (values[3][1] > ( 3 * max )) ||
196  (values[3][1] < ( 3 * min )) ) {
197  test_fail( __FILE__, __LINE__, "FLOP Col4!=3*Col2", 1 );
198  }
199  /* Check constraint col4 == col5 */
200  if (values[3][1] != values[4][1]) {
201  test_fail( __FILE__, __LINE__, "FLOP Col4!=Col5", 1 );
202  }
203  /* Check flops are sane */
204  if (values[0][1] < ( long long ) NUM_FLOPS ) {
205  test_fail( __FILE__, __LINE__, "FLOP sanity", 1 );
206  }
207 
208 
209  test_pass( __FILE__, values, num_tests );
210  return 0;
211 
212 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
int PAPI_event[2]
Definition: data_range.c:24
off64_t max
Definition: libasync.c:331
int PAPI_reset(int EventSet)
Definition: papi.c:2403
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
int num_events
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 TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
char * stringify_all_domains(int domains)
Definition: test_utils.c:369
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
#define TAB5
Definition: papi_test.h:116
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:680
#define PAPI_DEFGRN
Definition: papi.h:432
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
#define PAPI_DEFDOM
Definition: papi.h:430
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2503
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
#define PAPI_VER_CURRENT
Definition: papi.h:223
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277

Here is the call graph for this function:

Variable Documentation

int TESTS_QUIET

Definition at line 11 of file test_utils.c.