PAPI 7.1.0.0
Loading...
Searching...
No Matches
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++) {
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++) {
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}
double tmp
int i
#define MAX_CPUS
add PAPI preset or native hardware event by name to an EventSet
Assign a component index to an existing but empty EventSet.
Create a new empty PAPI EventSet.
get information about the system hardware
Get PAPI library or event set options.
initialize the PAPI library.
Set PAPI library or event set options.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Returns a string describing the PAPI error code.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_CPU_ATTACH
Definition: f90papi.h:19
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_GRANUL
Definition: f90papi.h:179
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_cpus
Definition: linux-rapl.c:161
void do_flops(int n)
Definition: multiplex.c:23
static options_t options
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
unsigned int cpu_num
Definition: papi.h:818
Hardware info structure.
Definition: papi.h:774
int totalcpus
Definition: papi.h:780
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
PAPI_cpu_option_t cpu
Definition: papi.h:852
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: