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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 26 of file attach_cpu.c.

27 {
28  int num_tests=1;
29  int num_events=1;
30  int retval;
31  int cpu_num = 1;
32  int EventSet1 = PAPI_NULL;
33  long long **values;
34  char event_name[PAPI_MAX_STR_LEN] = "PAPI_TOT_CYC";
35  PAPI_option_t opts;
36  int quiet;
37 
38  /* Set TESTS_QUIET variable */
39  quiet=tests_quiet( argc, argv );
40 
41  // user can provide cpu number on which to count events as arg 1
42  if (argc > 1) {
43  retval = atoi(argv[1]);
44  if (retval >= 0) {
45  cpu_num = retval;
46  }
47  }
48 
50  if ( retval != PAPI_VER_CURRENT )
51  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
52 
54  if ( retval != PAPI_OK )
55  test_fail( __FILE__, __LINE__, "PAPI_attach", retval );
56 
57  // Force event set to be associated with component 0 (perf_events component provides all core events)
59  if ( retval != PAPI_OK )
60  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval );
61 
62  // Attach this event set to cpu 1
63  opts.cpu.eventset = EventSet1;
64  opts.cpu.cpu_num = cpu_num;
65 
67  if ( retval != PAPI_OK ) {
68  if (!quiet) printf("Can't PAPI_CPU_ATTACH: %s\n",
70  test_skip( __FILE__, __LINE__, "PAPI_set_opt", retval );
71  }
72 
74  if ( retval != PAPI_OK ) {
75  if (!quiet) printf("Trouble adding event %s\n",event_name);
76  test_skip( __FILE__, __LINE__, "PAPI_add_named_event", retval );
77  }
78 
79  // get space for counter values (this needs to do this call because it malloc's space that test_pass and friends free)
81 
83  if ( retval != PAPI_OK ) {
84  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
85  }
86 
87  // do some work
89 
91  if ( retval != PAPI_OK )
92  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
93 
94  if (!quiet) printf ("Event: %s: %8lld on Cpu: %d\n", event_name, values[0][0], cpu_num);
95 
96  PAPI_shutdown( );
97 
98  test_pass( __FILE__ );
99 
100  return 0;
101 
102 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_OK
Definition: fpapi.h:105
int atoi()
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
#define PAPI_CPU_ATTACH
Definition: papi.h:458
void test_pass(const char *filename)
Definition: test_utils.c:432
static int num_events
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
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
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
#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
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
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
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
int EventSet1
Definition: zero_fork.c:47
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
Here is the call graph for this function: