PAPI 7.1.0.0
Loading...
Searching...
No Matches
powercap_basic_readwrite.c
Go to the documentation of this file.
1
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.h>
12
13#include "papi.h"
14#include "papi_test.h"
15
16#define PKG_POWER_LIMIT_A 3
17
18#ifdef BASIC_TEST
19
20void run_test( int quiet )
21{
22 if ( !quiet ) {
23 printf( "Sleeping 1 second...\n" );
24 }
25 sleep( 1 );
26}
27
28#else /* NOT BASIC_TEST */
29
30#define MATRIX_SIZE 1024
31static double a[MATRIX_SIZE][MATRIX_SIZE];
32static double b[MATRIX_SIZE][MATRIX_SIZE];
33static double c[MATRIX_SIZE][MATRIX_SIZE];
34
35/* Naive matrix multiply */
36void run_test( int quiet )
37{
38 double s;
39 int i,j,k;
40
41 if ( !quiet ) printf( "Doing a naive %dx%d MMM...\n",MATRIX_SIZE,MATRIX_SIZE );
42
43 for( i=0; i<MATRIX_SIZE; i++ ) {
44 for( j=0; j<MATRIX_SIZE; j++ ) {
45 a[i][j]=( double )i*( double )j;
46 b[i][j]=( double )i/( double )( j+5 );
47 }
48 }
49
50 for( j=0; j<MATRIX_SIZE; j++ ) {
51 for( i=0; i<MATRIX_SIZE; i++ ) {
52 s=0;
53 for( k=0; k<MATRIX_SIZE; k++ ) {
54 s+=a[i][k]*b[k][j];
55 }
56 c[i][j] = s;
57 }
58 }
59
60 s=0.0;
61 for( i=0; i<MATRIX_SIZE; i++ ) {
62 for( j=0; j<MATRIX_SIZE; j++ ) {
63 s+=c[i][j];
64 }
65 }
66
67 if ( !quiet ) printf( "Matrix multiply sum: s=%lf\n",s );
68}
69
70#endif
71
72int main ( int argc, char **argv )
73{
74 (void) argv;
75 (void) argc;
76 int retval,cid,powercap_cid=-1,numcmp;
77 int EventSet = PAPI_NULL;
78 long long values[1];
79 long long originalValues[1];
80 int code;
82 char event_descrs[1][PAPI_HUGE_STR_LEN];
83 char units[1][PAPI_MIN_STR_LEN];
84 int r;
85
86 const PAPI_component_info_t *cmpinfo = NULL;
87 PAPI_event_info_t evinfo;
88 double after_time;
89
90 /* Set TESTS_QUIET variable */
91 tests_quiet( argc, argv );
92
93 /* PAPI Initialization */
95 if ( retval != PAPI_VER_CURRENT )
96 test_fail( __FILE__, __LINE__,"PAPI_library_init failed\n",retval );
97
98 if ( !TESTS_QUIET ) printf( "Trying all powercap events\n" );
99
100 numcmp = PAPI_num_components();
101
102 for( cid=0; cid<numcmp; cid++ ) {
103
104 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
105 test_fail( __FILE__, __LINE__,"PAPI_get_component_info failed\n", 0 );
106
107 if ( strstr( cmpinfo->name,"powercap" ) ) {
108 powercap_cid=cid;
109 if ( !TESTS_QUIET ) printf( "Found powercap component at cid %d\n",powercap_cid );
110 if ( cmpinfo->disabled ) {
111 if ( !TESTS_QUIET ) {
112 printf( "powercap component disabled: %s\n",
113 cmpinfo->disabled_reason );
114 }
115 test_skip( __FILE__,__LINE__,"powercap component disabled",0 );
116 }
117 break;
118 }
119 }
120
121 /* Component not found */
122 if ( cid==numcmp )
123 test_skip( __FILE__,__LINE__,"No powercap component found\n",0 );
124
125 /* Skip if component has no counters */
126 if ( cmpinfo->num_cntrs==0 )
127 test_skip( __FILE__,__LINE__,"No counters in the powercap component\n",0 );
128
129 /* Create EventSet */
131 if ( retval != PAPI_OK )
132 test_fail( __FILE__, __LINE__, "PAPI_create_eventset()",retval );
133
134 /* Add all events, but one at a time */
135 printf( "\nThis test may take a few minutes to complete.\n\n" );
136 code = PAPI_NATIVE_MASK;
137 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, powercap_cid );
138 while ( r == PAPI_OK ) {
140 if ( retval != PAPI_OK )
141 test_fail( __FILE__, __LINE__,"Error from PAPI_event_code_to_name", retval );
142
143 retval = PAPI_get_event_info( code,&evinfo );
144 if ( retval != PAPI_OK )
145 test_fail( __FILE__, __LINE__, "Error getting event info\n",retval );
146
147 strncpy( event_descrs[0],evinfo.long_descr,PAPI_HUGE_STR_LEN );
148 strncpy( units[0],evinfo.units,PAPI_MIN_STR_LEN );
149
150 retval = PAPI_add_event( EventSet, code );
151
152 if ( retval != PAPI_OK )
153 break; /* We've hit an event limit */
154
155 /* Start Counting */
158 if ( retval != PAPI_OK )
159 test_fail( __FILE__, __LINE__, "PAPI_start()",retval );
160
161 /* Run test */
163
164 /* Read Counter before writing */
167 if ( retval != PAPI_OK )
168 test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
169
170 printf( "\n=======================================\n%-50s Readout (before 1st write) = %4.6f %s\n",
171 event_names[0], ( double )values[0]/1.0e0, units[0]);
172
173 /* Run test */
175
176 /* Write Counter to SAME value as was read */
177 originalValues[0] = values[0];
180 if ( retval != PAPI_OK )
181 test_fail( __FILE__, __LINE__, "PAPI_write()",retval );
182
183 /* Run test */
185
186 /* Read Counter after writing */
189 if ( retval != PAPI_OK )
190 test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
191
192 printf( "\n%-50s Readout (after 1st write) = %4.6f %s\n",
193 event_names[0], ( double )values[0]/1.0e0, units[0]);
194
195 /* Run test */
197
198 /* Write Counter back to ORIGINAL value that was read */
200 retval = PAPI_write( EventSet, originalValues );
201 if ( retval != PAPI_OK )
202 test_fail( __FILE__, __LINE__, "PAPI_write()",retval );
203
204 /* Run test */
206
207 /* Read Counter after writing original value back */
210 if ( retval != PAPI_OK )
211 test_fail( __FILE__, __LINE__, "PAPI_read()",retval );
212
213 printf( "\n%-50s Readout (after restoring write) = %4.6f %s\n",
214 event_names[0], ( double )values[0]/1.0e0, units[0]);
215
216 /* Run test */
218
219 /* Stop Counting */
222 if ( retval != PAPI_OK )
223 test_fail( __FILE__, __LINE__, "PAPI_stop()",retval );
224
225 if ( !TESTS_QUIET ) {
226 //printf( "\n=======================================\n");
227 printf( "\n%-50s Readout (final value) %4.6f %s\n",
228 event_names[0], ( double )values[0]/1.0e0, units[0]);
229 }
230
231 /* Clean-up event set before the next event is added */
233 if ( retval != PAPI_OK )
234 test_fail( __FILE__, __LINE__,"PAPI_cleanup_eventset()",retval );
235
236 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, powercap_cid );
237 }
238
239 /* Done, clean up */
241 if ( retval != PAPI_OK )
242 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset()",retval );
243
244 test_pass( __FILE__ );
245
246 return 0;
247}
248
static const char * event_names[2]
Definition: Gamum.c:27
int i
double s
Definition: byte_profile.c:36
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.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
Get the event's name and description info.
Get real time counter value in nanoseconds.
initialize the PAPI library.
Get the number of components available on the system.
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Write counter values into counters.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_MIN_STR_LEN
Definition: f90papi.h:208
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_HUGE_STR_LEN
Definition: f90papi.h:120
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_NATIVE_MASK
Return codes and api definitions.
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 main()
Definition: pernode.c:20
static double a[MATRIX_SIZE][MATRIX_SIZE]
static double b[MATRIX_SIZE][MATRIX_SIZE]
#define MATRIX_SIZE
static double c[MATRIX_SIZE][MATRIX_SIZE]
void run_test(int quiet)
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
int quiet
Definition: rapl_overflow.c:19
static long long after_time
Definition: rapl_overflow.c:15
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
int retval
Definition: zero_fork.c:53