PAPI 7.1.0.0
Loading...
Searching...
No Matches
powercap_basic_read.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#ifdef BASIC_TEST
17
18void run_test( int quiet )
19{
20 if ( !quiet ) {
21 printf( "Sleeping 1 second...\n" );
22 }
23 sleep( 1 );
24}
25
26#else /* NOT BASIC_TEST */
27
28#define MATRIX_SIZE 1024
29static double a[MATRIX_SIZE][MATRIX_SIZE];
30static double b[MATRIX_SIZE][MATRIX_SIZE];
31static double c[MATRIX_SIZE][MATRIX_SIZE];
32
33/* Naive matrix multiply */
34void run_test( int quiet )
35{
36 double s;
37 int i,j,k;
38
39 if ( !quiet ) printf( "Doing a naive %dx%d MMM...\n",MATRIX_SIZE,MATRIX_SIZE );
40
41 for( i=0; i<MATRIX_SIZE; i++ ) {
42 for( j=0; j<MATRIX_SIZE; j++ ) {
43 a[i][j]=( double )i*( double )j;
44 b[i][j]=( double )i/( double )( j+5 );
45 }
46 }
47
48 for( j=0; j<MATRIX_SIZE; j++ ) {
49 for( i=0; i<MATRIX_SIZE; i++ ) {
50 s=0;
51 for( k=0; k<MATRIX_SIZE; k++ ) {
52 s+=a[i][k]*b[k][j];
53 }
54 c[i][j] = s;
55 }
56 }
57
58 s=0.0;
59 for( i=0; i<MATRIX_SIZE; i++ ) {
60 for( j=0; j<MATRIX_SIZE; j++ ) {
61 s+=c[i][j];
62 }
63 }
64
65 if ( !quiet ) printf( "Matrix multiply sum: s=%lf\n",s );
66}
67
68#endif
69
70int main ( int argc, char **argv )
71{
72 (void) argv;
73 (void) argc;
74 int retval,cid,powercap_cid=-1,numcmp;
75 int EventSet = PAPI_NULL;
76 long long values[1];
77 int code;
79 char event_descrs[1][PAPI_HUGE_STR_LEN];
80 char units[1][PAPI_MIN_STR_LEN];
81 int r;
82
83 const PAPI_component_info_t *cmpinfo = NULL;
84 PAPI_event_info_t evinfo;
85
86 /* Set TESTS_QUIET variable */
87 tests_quiet( argc, argv );
88
89 /* PAPI Initialization */
91 if ( retval != PAPI_VER_CURRENT )
92 test_fail( __FILE__, __LINE__,"PAPI_library_init failed\n",retval );
93
94 if ( !TESTS_QUIET ) printf( "Trying all powercap events\n" );
95
96 numcmp = PAPI_num_components();
97
98 for( cid=0; cid<numcmp; cid++ ) {
99
100 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
101 test_fail( __FILE__, __LINE__,"PAPI_get_component_info failed\n", 0 );
102
103 if ( strstr( cmpinfo->name,"powercap" ) ) {
104 powercap_cid=cid;
105 if ( !TESTS_QUIET ) printf( "Found powercap component at cid %d\n",powercap_cid );
106 if ( cmpinfo->disabled ) {
107 if ( !TESTS_QUIET ) {
108 printf( "powercap component disabled: %s\n",
109 cmpinfo->disabled_reason );
110 }
111 test_skip( __FILE__,__LINE__,"powercap component disabled",0 );
112 }
113 break;
114 }
115 }
116
117 /* Component not found */
118 if ( cid==numcmp )
119 test_skip( __FILE__,__LINE__,"No powercap component found\n",0 );
120
121 /* Skip if component has no counters */
122 if ( cmpinfo->num_cntrs==0 )
123 test_skip( __FILE__,__LINE__,"No counters in the powercap component\n",0 );
124
125 /* Create EventSet */
127 if ( retval != PAPI_OK )
128 test_fail( __FILE__, __LINE__, "PAPI_create_eventset()",retval );
129
130 /* Add all events, but one at a time */
131 printf( "\nThis test may take a few minutes to complete.\n\n" );
132 code = PAPI_NATIVE_MASK;
133 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, powercap_cid );
134 while ( r == PAPI_OK ) {
136 if ( retval != PAPI_OK )
137 test_fail( __FILE__, __LINE__,"Error from PAPI_event_code_to_name", retval );
138
139 retval = PAPI_get_event_info( code,&evinfo );
140 if ( retval != PAPI_OK )
141 test_fail( __FILE__, __LINE__, "Error getting event info\n",retval );
142
143 strncpy( event_descrs[0],evinfo.long_descr,PAPI_HUGE_STR_LEN );
144 strncpy( units[0],evinfo.units,PAPI_MIN_STR_LEN );
145
146 retval = PAPI_add_event( EventSet, code );
147
148 if ( retval != PAPI_OK )
149 break; /* We've hit an event limit */
150
151 /* Start Counting */
153 if ( retval != PAPI_OK )
154 test_fail( __FILE__, __LINE__, "PAPI_start()",retval );
155
156 /* Run test */
158
159 /* Stop Counting */
161 if ( retval != PAPI_OK )
162 test_fail( __FILE__, __LINE__, "PAPI_stop()",retval );
163
164 if ( !TESTS_QUIET ) {
165 printf( "\n" );
166 printf( "%-50s%4.6f %s\n",
167 event_names[0], ( double )values[0]/1.0e0, units[0]);
168 }
169
170 /* Clean-up event set before the next event is added */
172 if ( retval != PAPI_OK )
173 test_fail( __FILE__, __LINE__,"PAPI_cleanup_eventset()",retval );
174
175 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, powercap_cid );
176 }
177
178 /* Done, clean up */
180 if ( retval != PAPI_OK )
181 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset()",retval );
182
183 test_pass( __FILE__ );
184
185 return 0;
186}
187
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.
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 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
Tests basic reading functionality of powercap component.
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
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