PAPI  5.6.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)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file first.c.

35 {
36  int retval, num_tests = 5, num_events, tmp;
37  long long **values;
38  int EventSet = PAPI_NULL;
39  char event_name1[]="PAPI_TOT_CYC";
40  char event_name2[]="PAPI_TOT_INS";
41  char add_event_str[PAPI_MAX_STR_LEN];
42  long long min, max;
43  int quiet;
44 
45  /* Set TESTS_QUIET variable */
46  quiet = tests_quiet( argc, argv );
47 
48  /* Init PAPI library */
50  if ( retval != PAPI_VER_CURRENT ) {
51  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
52  }
53 
54  /* create the eventset */
55  retval = PAPI_create_eventset( &EventSet );
56  if ( retval != PAPI_OK ) {
57  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
58  }
59 
60  retval = PAPI_add_named_event( EventSet, event_name1);
61  if ( retval != PAPI_OK ) {
62  if (!quiet) printf("Couldn't add %s\n",event_name1);
63  test_skip(__FILE__,__LINE__,"Couldn't add PAPI_TOT_CYC",0);
64  }
65 
66  retval = PAPI_add_named_event( EventSet, event_name2);
67  if ( retval != PAPI_OK ) {
68  if (!quiet) printf("Couldn't add %s\n",event_name2);
69  test_skip(__FILE__,__LINE__,"Couldn't add PAPI_TOT_INS",0);
70  }
71 
72  num_events=2;
73 
74  sprintf( add_event_str, "PAPI_add_event[%s]", event_name2 );
75 
76  /* Allocate space for results */
77  values = allocate_test_space( num_tests, num_events );
78 
79  /* Start PAPI */
80  retval = PAPI_start( EventSet );
81  if ( retval != PAPI_OK ) {
82  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
83  }
84 
85  /* Benchmark code */
87 
88  /* read results 0 */
89  retval = PAPI_read( EventSet, values[0] );
90  if ( retval != PAPI_OK ) {
91  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
92  }
93 
94  /* Reset */
95  retval = PAPI_reset( EventSet );
96  if ( retval != PAPI_OK ) {
97  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
98  }
99 
100  /* Benchmark some more */
101  do_flops( NUM_FLOPS );
102 
103  /* Read Results 1 */
104  retval = PAPI_read( EventSet, values[1] );
105  if ( retval != PAPI_OK ) {
106  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
107  }
108 
109  /* Benchmark some more */
110  do_flops( NUM_FLOPS );
111 
112  /* Read results 2 */
113  retval = PAPI_read( EventSet, values[2] );
114  if ( retval != PAPI_OK ) {
115  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
116  }
117 
118  /* Benchmark some more */
119  do_flops( NUM_FLOPS );
120 
121  /* Read results 3 */
122  retval = PAPI_stop( EventSet, values[3] );
123  if ( retval != PAPI_OK ) {
124  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
125  }
126 
127  /* Read results 4 */
128  retval = PAPI_read( EventSet, values[4] );
129  if ( retval != PAPI_OK ) {
130  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
131  }
132 
133  /* remove results. We never stop??? */
134  PAPI_remove_named_event(EventSet,event_name1);
135  PAPI_remove_named_event(EventSet,event_name2);
136 
137  if ( !quiet ) {
138  printf( "Test case 1: Non-overlapping start, stop, read.\n" );
139  printf( "-----------------------------------------------\n" );
140  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
141  printf( "Default domain is: %d (%s)\n", tmp,
142  stringify_all_domains( tmp ) );
143  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
144  printf( "Default granularity is: %d (%s)\n", tmp,
145  stringify_granularity( tmp ) );
146  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
147  printf( "-------------------------------------------------------------------------\n" );
148 
149  printf( "Test type : 1 2 3 4 5\n" );
150  sprintf( add_event_str, "%s:", event_name2 );
151  printf( TAB5, add_event_str,
152  values[0][1], values[1][1], values[2][1],
153  values[3][1], values[4][1] );
154  printf( TAB5, "PAPI_TOT_CYC:",
155  values[0][0], values[1][0], values[2][0],
156  values[3][0], values[4][0] );
157  printf( "-------------------------------------------------------------------------\n" );
158 
159  printf( "Verification:\n" );
160  printf( "Row 1 Column 1 at least %d\n", NUM_FLOPS );
161  printf( "%% difference between %s 1 & 2: %.2f\n",
162  add_event_str,
163  100.0 * ( float ) values[0][1] /
164  ( float ) values[1][1] );
165  printf( "%% difference between %s 1 & 2: %.2f\n",
166  "PAPI_TOT_CYC",
167  100.0 * ( float ) values[0][0] /
168  ( float ) values[1][0] );
169  printf( "Column 1 approximately equals column 2\n" );
170  printf( "Column 3 approximately equals 2 * column 2\n" );
171  printf( "Column 4 approximately equals 3 * column 2\n" );
172  printf( "Column 4 exactly equals column 5\n" );
173  }
174 
175  /* Validation */
176 
177  /* Check cycles constraints */
178 
179  min = ( long long ) ( ( double ) values[1][0] * .8 );
180  max = ( long long ) ( ( double ) values[1][0] * 1.2 );
181 
182  /* Check constraint Col1=Col2 */
183  if ( values[0][0] > max || values[0][0] < min ) {
184  test_fail( __FILE__, __LINE__, "Cycle Col1!=Col2", 1 );
185  }
186  /* Check constraint col3 == 2*col2 */
187  if ( (values[2][0] > ( 2 * max )) ||
188  (values[2][0] < ( 2 * min )) ) {
189  test_fail( __FILE__, __LINE__, "Cycle Col3!=2*Col2", 1 );
190  }
191  /* Check constraint col4 == 3*col2 */
192  if ( (values[3][0] > ( 3 * max )) ||
193  (values[3][0] < ( 3 * min )) ) {
194  test_fail( __FILE__, __LINE__, "Cycle Col3!=3*Col2", 1 );
195  }
196  /* Check constraint col4 == col5 */
197  if ( values[3][0] != values[4][0] ) {
198  test_fail( __FILE__, __LINE__, "Cycle Col4!=Col5", 1 );
199  }
200 
201 
202  /* Check FLOP constraints */
203 
204  min = ( long long ) ( ( double ) values[1][1] * .9 );
205  max = ( long long ) ( ( double ) values[1][1] * 1.1 );
206 
207  /* Check constraint Col1=Col2 */
208  if ( values[0][1] > max || values[0][1] < min ) {
209  test_fail( __FILE__, __LINE__, "FLOP Col1!=Col2", 1 );
210  }
211  /* Check constraint col3 == 2*col2 */
212  if ( (values[2][1] > ( 2 * max )) ||
213  (values[2][1] < ( 2 * min )) ) {
214  test_fail( __FILE__, __LINE__, "FLOP Col3!=2*Col2", 1 );
215  }
216  /* Check constraint col4 == 3*col2 */
217  if ( (values[3][1] > ( 3 * max )) ||
218  (values[3][1] < ( 3 * min )) ) {
219  test_fail( __FILE__, __LINE__, "FLOP Col4!=3*Col2", 1 );
220  }
221  /* Check constraint col4 == col5 */
222  if (values[3][1] != values[4][1]) {
223  test_fail( __FILE__, __LINE__, "FLOP Col4!=Col5", 1 );
224  }
225  /* Check flops are sane */
226  if (values[0][1] < ( long long ) NUM_FLOPS ) {
227  test_fail( __FILE__, __LINE__, "FLOP sanity", 1 );
228  }
229 
230  test_pass( __FILE__ );
231 
232  return 0;
233 
234 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
off64_t max
Definition: libasync.c:331
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_reset(int EventSet)
Definition: papi.c:2459
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define PAPI_NULL
Definition: papi.h:292
static int num_events
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
#define TAB5
Definition: papi_test.h:92
#define PAPI_DEFGRN
Definition: papi.h:434
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
#define PAPI_DEFDOM
Definition: papi.h:432
int PAPI_remove_named_event(int EventSet, const char *EventName)
Definition: papi.c:1961
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:46
#define PAPI_VER_CURRENT
Definition: papi.h:225

Here is the call graph for this function: