PAPI  5.7.0.0
attach_cpu_validate.c File Reference
Include dependency graph for attach_cpu_validate.c:

Go to the source code of this file.

Macros

#define MAX_CPUS   16
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAX_CPUS

#define MAX_CPUS   16

Definition at line 15 of file attach_cpu_validate.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 18 of file attach_cpu_validate.c.

19 {
20  int i;
21  int retval;
22  int num_cpus = 8;
23  int EventSet[MAX_CPUS];
24  const PAPI_hw_info_t *hwinfo;
25  double diff;
26 
27  long long values[MAX_CPUS];
28  char event_name[PAPI_MAX_STR_LEN] = "PAPI_TOT_INS";
29  PAPI_option_t opts;
30  int quiet;
31  long long average=0;
32  int same=0;
33 
34  /* Set TESTS_QUIET variable */
35  quiet=tests_quiet( argc, argv );
36 
38  if ( retval != PAPI_VER_CURRENT ) {
39  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
40  }
41 
42  hwinfo = PAPI_get_hardware_info( );
43  if ( hwinfo==NULL) {
44  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", retval );
45  }
46 
47  num_cpus=hwinfo->totalcpus;
48 
49  if ( num_cpus < 2 ) {
50  if (!quiet) printf("Need at least 1 CPU\n");
51  test_skip( __FILE__, __LINE__, "num_cpus", 0 );
52  }
53 
54  if (num_cpus > MAX_CPUS) {
56  }
57 
58  for(i=0;i<num_cpus;i++) {
59 
61 
63  if ( retval != PAPI_OK ) {
64  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
65  }
66 
67  /* Force event set to be associated with component 0 */
68  /* (perf_events component provides all core events) */
70  if ( retval != PAPI_OK ) {
71  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
72  }
73 
74  /* Attach this event set to cpu i */
75  opts.cpu.eventset = EventSet[i];
76  opts.cpu.cpu_num = i;
77 
79  if ( retval != PAPI_OK ) {
80  if (!quiet) printf("Can't PAPI_CPU_ATTACH: %s\n",
82  test_skip( __FILE__, __LINE__, "PAPI_set_opt", retval );
83  }
84 
86  if ( retval != PAPI_OK ) {
87  if (!quiet) printf("Trouble adding event %s\n",event_name);
88  test_skip( __FILE__, __LINE__, "PAPI_add_named_event", retval );
89  }
90  }
91 
92 
93  int tmp;
95 
96  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
97  if (!quiet) {
98  printf( "Default granularity is: %d (%s)\n", tmp,
100  }
101 
102  options.granularity.eventset = EventSet[0];
104  if (!quiet) {
105  printf( "Eventset[0] granularity is: %d (%s)\n", options.granularity.granularity,
106  stringify_granularity( options.granularity.granularity ) );
107  }
108 
109  for(i=0;i<num_cpus;i++) {
110  retval = PAPI_start( EventSet[i] );
111  if ( retval != PAPI_OK ) {
112  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
113  }
114  }
115 
116  // do some work
118 
119  for(i=0;i<num_cpus;i++) {
120  retval = PAPI_stop( EventSet[i], &values[i] );
121  if ( retval != PAPI_OK ) {
122  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
123  }
124  }
125 
126  for(i=0;i<num_cpus;i++) {
127  if (!quiet) {
128  printf ("Event: %s: %10lld on Cpu: %d\n",
129  event_name, values[i], i);
130  }
131  }
132 
133  for(i=0;i<num_cpus;i++) {
134  average+=values[i];
135  }
136  average/=num_cpus;
137  if (!quiet) {
138  printf("Average: %10lld\n",average);
139  }
140 
141 
142  for(i=0;i<num_cpus;i++) {
143  diff=((double)values[i]-(double)average)/(double)average;
144  if ((diff<0.01) && (diff>-0.01)) same++;
145  }
146 
147  if (same) {
148  if (!quiet) {
149  printf("Error! %d events were the same\n",same);
150  }
151  test_fail( __FILE__, __LINE__, "Too similar", 0 );
152  }
153 
154  PAPI_shutdown( );
155 
156  test_pass( __FILE__ );
157 
158  return 0;
159 
160 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define PAPI_GRANUL
Definition: fpapi.h:52
#define PAPI_CPU_ATTACH
Definition: papi.h:458
void test_pass(const char *filename)
Definition: test_utils.c:432
Hardware info structure.
Definition: papi.h:781
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define MAX_CPUS
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
int retval
Definition: zero_fork.c:53
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:849
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3465
unsigned int cpu_num
Definition: papi.h:825
double tmp
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
int PAPI_library_init(int version)
Definition: papi.c:500
void PAPI_shutdown(void)
Definition: papi.c:4461
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
#define PAPI_NULL
Definition: fpapi.h:13
PAPI_cpu_option_t cpu
Definition: papi.h:859
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
static int num_cpus
Definition: linux-rapl.c:150
void do_flops(int n)
Definition: multiplex.c:23
#define PAPI_DEFGRN
Definition: fpapi.h:51
char * PAPI_strerror(int errorCode)
Definition: papi.c:4603
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
static options_t options
int totalcpus
Definition: papi.h:787
int PAPI_start(int EventSet)
Definition: papi.c:2096
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int i
Definition: fileop.c:140
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
Here is the call graph for this function: