PAPI 7.1.0.0
Loading...
Searching...
No Matches
example_multiple_components.c File Reference

This tests to see if the CPU component and Example component can be used simultaneously. More...

Include dependency graph for example_multiple_components.c:

Go to the source code of this file.

Macros

#define NUM_EVENTS   1
 

Functions

int main (int argc, char **argv)
 

Detailed Description

Author
Vince Weaver vweav.nosp@m.er1@.nosp@m.eecs..nosp@m.utk..nosp@m.edu test if multiple components can be used at once

Definition in file example_multiple_components.c.

Macro Definition Documentation

◆ NUM_EVENTS

#define NUM_EVENTS   1

Definition at line 24 of file example_multiple_components.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 26 of file example_multiple_components.c.

27{
28
29 int retval;
31 long long values1[NUM_EVENTS];
32 long long values2[NUM_EVENTS];
33 const PAPI_component_info_t *cmpinfo = NULL;
34 int numcmp,cid,example_cid=-1;
35 int code;
36 int quiet=0;
37
38 /* Set TESTS_QUIET variable */
39 quiet=tests_quiet( argc, argv );
40
41 /* PAPI Initialization */
43 if ( retval != PAPI_VER_CURRENT ) {
44 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
45 }
46
47 if (!quiet) {
48 printf( "Testing simultaneous component use with PAPI %d.%d.%d\n",
52 }
53
54 /* Find our component */
55
56 numcmp = PAPI_num_components();
57 for( cid=0; cid<numcmp; cid++) {
58 if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
59 test_fail(__FILE__, __LINE__,
60 "PAPI_get_component_info failed\n", 0);
61 }
62 if (!quiet) {
63 printf("\tComponent %d - %d events - %s\n", cid,
64 cmpinfo->num_native_events,
65 cmpinfo->name);
66 }
67 if (strstr(cmpinfo->name,"example")) {
68 /* FOUND! */
69 example_cid=cid;
70 }
71 }
72
73
74 if (example_cid<0) {
75 test_skip(__FILE__, __LINE__,
76 "Example component not found\n", 0);
77 }
78
79 if (!quiet) {
80 printf("\nFound Example Component at id %d\n",example_cid);
81 }
82
83
84 /* Create an eventset for the Example component */
85
87 if ( retval != PAPI_OK ) {
88 test_fail( __FILE__, __LINE__,
89 "PAPI_create_eventset() failed\n", retval );
90 }
91
92 retval = PAPI_event_name_to_code("EXAMPLE_CONSTANT", &code);
93 if ( retval != PAPI_OK ) {
94 test_fail( __FILE__, __LINE__,
95 "EXAMPLE_ZERO not found\n",retval );
96 }
97
99 if ( retval != PAPI_OK ) {
100 test_fail( __FILE__, __LINE__,
101 "PAPI_add_events failed\n", retval );
102 }
103
104
105 /* Create an eventset for the CPU component */
106
108 if ( retval != PAPI_OK ) {
109 test_fail( __FILE__, __LINE__,
110 "PAPI_create_eventset() failed\n", retval );
111 }
112
113 retval = PAPI_event_name_to_code("PAPI_TOT_CYC", &code);
114 if ( retval != PAPI_OK ) {
115 test_skip( __FILE__, __LINE__,
116 "PAPI_TOT_CYC not available\n",retval );
117 }
118
120 if ( retval != PAPI_OK ) {
121 test_skip( __FILE__, __LINE__,
122 "NO CPU component found\n", retval );
123 }
124
125 if (!quiet) printf("\nStarting EXAMPLE_CONSTANT and PAPI_TOT_CYC at the same time\n");
126
127 /* Start CPU component event */
129 if ( retval != PAPI_OK ) {
130 test_fail( __FILE__, __LINE__,
131 "PAPI_start failed\n",retval );
132 }
133
134 /* Start example component */
136 if ( retval != PAPI_OK ) {
137 test_fail( __FILE__, __LINE__,
138 "PAPI_start failed\n",retval );
139 }
140
141
142
143
144 /* Stop example component */
145 retval = PAPI_stop( EventSet1, values1 );
146 if ( retval != PAPI_OK ) {
147 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
148 }
149
150 /* Stop CPU component */
151 retval = PAPI_stop( EventSet2, values2 );
152 if ( retval != PAPI_OK ) {
153 test_fail( __FILE__, __LINE__, "PAPI_stop failed\n", retval);
154 }
155
156 if (!quiet) printf("Stopping EXAMPLE_CONSTANT and PAPI_TOT_CYC\n\n");
157
158
159 if (!quiet) printf("Results from EXAMPLE_CONSTANT: %lld\n",values1[0]);
160
161 if (values1[0]!=42) {
162 test_fail( __FILE__, __LINE__, "Result should be 42!\n", 0);
163 }
164
165 if (!quiet) printf("Results from PAPI_TOT_CYC: %lld\n\n",values2[0]);
166
167 if (values2[0]<1) {
168 test_fail( __FILE__, __LINE__, "Result should greater than 0\n", 0);
169 }
170
171 /* Cleanup EventSets */
173 if (retval != PAPI_OK) {
174 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
175 }
176
178 if (retval != PAPI_OK) {
179 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset!\n", retval);
180 }
181
182 /* Destroy EventSets */
184 if (retval != PAPI_OK) {
185 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset!\n", retval);
186 }
187
188 test_pass( __FILE__ );
189
190 return 0;
191}
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a name to a numeric hardware event code.
get information about a specific software component
initialize the PAPI library.
Get the number of components available on the system.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define NUM_EVENTS
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_VERSION
Definition: f90papi.h:193
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_VERSION_REVISION(x)
Definition: papi.h:221
#define PAPI_VERSION_MAJOR(x)
Definition: papi.h:219
#define PAPI_VERSION_MINOR(x)
Definition: papi.h:220
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
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
int EventSet2
Definition: rapl_overflow.c:17
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
int EventSet1
Definition: zero_fork.c:47
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: