PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zero_named.c File Reference
Include dependency graph for zero_named.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 14 of file zero_named.c.

15 {
16  int retval, num_tests = 1, tmp;
17  int EventSet = PAPI_NULL;
18  int num_events = 2;
19  long long **values;
20  long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
21  const char *event_names[] = {"PAPI_TOT_CYC","PAPI_TOT_INS"};
22  char add_event_str[PAPI_MAX_STR_LEN];
23  double cycles_error;
24  int quiet;
25 
26  /* Set TESTS_QUIET variable */
27  quiet=tests_quiet( argc, argv );
28 
29  /* Init the PAPI library */
31  if ( retval != PAPI_VER_CURRENT ) {
32  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33  }
34 
35  /* Verify that the named events exist */
36  retval = PAPI_query_named_event(event_names[0]);
37  if ( retval == PAPI_OK) {
38  retval = PAPI_query_named_event(event_names[1]);
39  }
40  if ( retval != PAPI_OK ) {
41  if (!quiet) printf("Trouble querying events\n");
42  test_skip( __FILE__, __LINE__, "PAPI_query_named_event", retval );
43  }
44 
45  /* Create an empty event set */
46  retval = PAPI_create_eventset( &EventSet );
47  if ( retval != PAPI_OK )
48  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
49 
50  /* add the events named above */
51  retval = PAPI_add_named_event( EventSet, event_names[0] );
52  if ( retval != PAPI_OK ) {
53  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
54  test_fail( __FILE__, __LINE__, add_event_str, retval );
55  }
56 
57  retval = PAPI_add_named_event( EventSet, event_names[1] );
58  if ( retval != PAPI_OK ) {
59  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
60  test_fail( __FILE__, __LINE__, add_event_str, retval );
61  }
62 
63  values = allocate_test_space( num_tests, num_events );
64 
65  /* Gather before stats */
66  elapsed_us = PAPI_get_real_usec( );
67  elapsed_cyc = PAPI_get_real_cyc( );
68  elapsed_virt_us = PAPI_get_virt_usec( );
69  elapsed_virt_cyc = PAPI_get_virt_cyc( );
70 
71  /* Start PAPI */
72  retval = PAPI_start( EventSet );
73  if ( retval != PAPI_OK ) {
74  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
75  }
76 
77  /* our test code */
79 
80  /* Stop PAPI */
81  retval = PAPI_stop( EventSet, values[0] );
82  if ( retval != PAPI_OK ) {
83  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
84  }
85 
86  /* Calculate total values */
87  elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
88  elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
89  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
90  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
91 
92  /* remove PAPI_TOT_CYC and PAPI_TOT_INS */
93  retval = PAPI_remove_named_event( EventSet, event_names[0] );
94  if ( retval != PAPI_OK ) {
95  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
96  test_fail( __FILE__, __LINE__, add_event_str, retval );
97  }
98 
99  retval = PAPI_remove_named_event( EventSet, event_names[1] );
100  if ( retval != PAPI_OK ) {
101  sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
102  test_fail( __FILE__, __LINE__, add_event_str, retval );
103  }
104 
105  if ( !quiet ) {
106  printf( "PAPI_{query, add, remove}_named_event API test.\n" );
107  printf( "-----------------------------------------------\n" );
108  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
109  printf( "Default domain is: %d (%s)\n", tmp,
111  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
112  printf( "Default granularity is: %d (%s)\n", tmp,
114  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
115  printf( "-------------------------------------------------------------------------\n" );
116 
117  printf( "Test type : \t 1\n" );
118 
119  /* cycles is first, other event second */
120  sprintf( add_event_str, "%-12s : \t", event_names[0] );
121  printf( TAB1, add_event_str, values[0][0] );
122  sprintf( add_event_str, "%-12s : \t", event_names[1] );
123  printf( TAB1, add_event_str, values[0][1] );
124 
125  printf( TAB1, "Real usec : \t", elapsed_us );
126  printf( TAB1, "Real cycles : \t", elapsed_cyc );
127  printf( TAB1, "Virt usec : \t", elapsed_virt_us );
128  printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
129 
130  printf( "-------------------------------------------------------------------------\n" );
131 
132  printf( "Verification: PAPI_TOT_CYC should be roughly real_cycles\n" );
133  cycles_error=100.0*((double)values[0][0] - (double)elapsed_cyc)/
134  (double)values[0][0];
135  if (cycles_error>10.0) {
136  printf("Error of %.2f%%\n",cycles_error);
137  test_fail( __FILE__, __LINE__, "validation", 0 );
138  }
139 
140  }
141  test_pass( __FILE__ );
142 
143  return 0;
144 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
void test_pass(const char *filename)
Definition: test_utils.c:432
long long PAPI_get_virt_usec(void)
Definition: papi.c:6372
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6300
#define PAPI_NULL
Definition: papi.h:292
static int num_events
#define TAB1
Definition: papi_test.h:88
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
static double
Definition: fileop.c:1281
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
long long elapsed_cyc
Definition: zero_fork.c:50
int PAPI_query_named_event(const char *EventName)
Definition: papi.c:756
#define PAPI_DEFGRN
Definition: papi.h:434
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
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
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
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
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 elapsed_us
Definition: zero_fork.c:50
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: