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

Go to the source code of this file.

Functions

void init_papi (void)
 
int case1 (void)
 
int main (int argc, char **argv)
 

Function Documentation

int case1 ( void  )

Definition at line 31 of file multiplex2.c.

32 {
33  int retval, i, EventSet = PAPI_NULL, j = 0, k = 0, allvalid = 1;
34  int max_mux, nev, *events;
35  long long *values;
36  PAPI_event_info_t pset;
37  char evname[PAPI_MAX_STR_LEN];
38 
39  init_papi( );
40  init_multiplex( );
41 
42 #if 0
44  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
45 #endif
46  retval = PAPI_create_eventset( &EventSet );
47  if ( retval != PAPI_OK )
48  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
49 
50 #if 0
52  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
53 #endif
54  /* In Component PAPI, EventSets must be assigned a component index
55  before you can fiddle with their internals.
56  0 is always the cpu component */
57  retval = PAPI_assign_eventset_component( EventSet, 0 );
58  if ( retval != PAPI_OK )
59  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
60  retval );
61 #if 0
63  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
64 #endif
65 
66  retval = PAPI_set_multiplex( EventSet );
67  if ( retval == PAPI_ENOSUPP) {
68  test_skip(__FILE__, __LINE__, "Multiplex not supported", 1);
69  }
70  else if ( retval != PAPI_OK )
71  test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval );
72 
73  max_mux = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL );
74  if ( max_mux > 32 )
75  max_mux = 32;
76 
77 #if 0
79  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
80 #endif
81 
82  /* Fill up the event set with as many non-derived events as we can */
83  printf
84  ( "\nFilling the event set with as many non-derived events as we can...\n" );
85 
86  i = PAPI_PRESET_MASK;
87  do {
88  if ( PAPI_get_event_info( i, &pset ) == PAPI_OK ) {
89  if ( pset.count && ( strcmp( pset.derived, "NOT_DERIVED" ) == 0 ) ) {
90  retval = PAPI_add_event( EventSet, ( int ) pset.event_code );
91  if ( retval != PAPI_OK ) {
92  printf("Failed trying to add %s\n",pset.symbol);
93  break;
94  }
95  else {
96  printf( "Added %s\n", pset.symbol );
97  j++;
98  }
99  }
100  }
101  } while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ) &&
102  ( j < max_mux ) );
103 
104  events = ( int * ) malloc( ( size_t ) j * sizeof ( int ) );
105  if ( events == NULL )
106  test_fail( __FILE__, __LINE__, "malloc events", 0 );
107 
108  values = ( long long * ) malloc( ( size_t ) j * sizeof ( long long ) );
109  if ( values == NULL )
110  test_fail( __FILE__, __LINE__, "malloc values", 0 );
111 
112  do_stuff( );
113 
114 #if 0
116  test_fail( __FILE__, __LINE__, "PAPI_set_domain", retval );
117 #endif
118 
119  if ( PAPI_start( EventSet ) != PAPI_OK )
120  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
121 
122  do_stuff( );
123 
124  retval = PAPI_stop( EventSet, values );
125  if ( retval != PAPI_OK )
126  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
127 
128  nev = j;
129  retval = PAPI_list_events( EventSet, events, &nev );
130  if ( retval != PAPI_OK )
131  test_fail( __FILE__, __LINE__, "PAPI_list_events", retval );
132 
133  printf( "\nEvent Counts:\n" );
134  for ( i = 0, allvalid = 0; i < j; i++ ) {
135  PAPI_event_code_to_name( events[i], evname );
136  printf( TAB1, evname, values[i] );
137  if ( values[i] == 0 )
138  allvalid++;
139  }
140  printf( "\n" );
141  if ( allvalid ) {
142  printf( "Caution: %d counters had zero values\n", allvalid );
143  }
144 
145  if (allvalid==j) {
146  test_fail( __FILE__, __LINE__, "All counters returned zero", 5 );
147  }
148 
149  for ( i = 0, allvalid = 0; i < j; i++ ) {
150  for ( k = i + 1; k < j; k++ ) {
151  if ( ( i != k ) && ( values[i] == values[k] ) ) {
152  allvalid++;
153  break;
154  }
155  }
156  }
157 
158  if ( allvalid ) {
159  printf( "Caution: %d counter pair(s) had identical values\n",
160  allvalid );
161  }
162 
163  free( events );
164  free( values );
165 
166  retval = PAPI_cleanup_eventset( EventSet );
167  if ( retval != PAPI_OK )
168  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
169 
170  retval = PAPI_destroy_eventset( &EventSet );
171  if ( retval != PAPI_OK )
172  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
173 
174  return ( SUCCESS );
175 }
unsigned int count
Definition: papi.h:984
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1622
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
#define PAPI_ENOSUPP
Definition: papi.h:269
#define PAPI_NULL
Definition: papi.h:290
void do_stuff(void)
Definition: do_loops.c:249
#define PAPI_DOM_KERNEL
Definition: papi.h:298
#define TAB1
Definition: papi_test.h:112
int EventSet
Definition: data_range.c:25
int PAPI_enum_event(int *EventCode, int modifier)
Definition: papi.c:1150
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
return PAPI_OK
Definition: linux-nvml.c:458
#define SUCCESS
Definition: test_utils.h:5
#define PAPI_PRESET_MASK
#define printf
Definition: papi_test.h:125
void init_multiplex(void)
Definition: test_utils.c:892
void init_papi(int *out_events, int *len)
Definition: multiplex1.c:33
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:846
char events[MAX_EVENTS][BUFSIZ]
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int i
Definition: fileop.c:140
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
free(dummyfile[xx])
int k
Definition: iozone.c:19136
long long
Definition: iozone.c:19827
#define PAPI_MAX_MPX_CTRS
Definition: papi.h:437
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2834
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1485
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
int
Definition: iozone.c:18528
int PAPI_set_multiplex(int EventSet)
Definition: papi.c:3277
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int PAPI_set_domain(int domain)
Definition: papi.c:5614
int PAPI_start(int EventSet)
Definition: papi.c:2053
long j
Definition: iozone.c:19135
unsigned int event_code
Definition: papi.h:961
char derived[PAPI_MIN_STR_LEN]
Definition: papi.h:992
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
int PAPI_list_events(int EventSet, int *Events, int *number)
Definition: papi.c:5927

Here is the call graph for this function:

void init_papi ( void  )

Definition at line 16 of file multiplex2.c.

17 {
18  int retval;
19 
20  /* Initialize the library */
21 
23  if ( retval != PAPI_VER_CURRENT )
24  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
25 
26 }
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:223

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 178 of file multiplex2.c.

179 {
180 
181  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
182 
183  printf( "%s: Does PAPI_multiplex_init() handle lots of events?\n",
184  argv[0] );
185  printf( "Using %d iterations\n", NUM_ITERS );
186 
187  case1( );
188  test_pass( __FILE__, NULL, 0 );
189  exit( 1 );
190 }
#define NUM_ITERS
Definition: multiplex.c:19
tests_quiet(argc, argv)
int case1()
Definition: multiplex1.c:90
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
void exit()

Here is the call graph for this function: