PAPI 7.1.0.0
Loading...
Searching...
No Matches
kufrin.c File Reference
Include dependency graph for kufrin.c:

Go to the source code of this file.

Functions

double loop (long n)
 
void * thread (void *arg)
 
int main (int argc, char **argv)
 

Variables

static intevents
 
static int numevents = 0
 
static int max_events =0
 

Function Documentation

◆ loop()

double loop ( long  n)

Definition at line 26 of file kufrin.c.

27{
28 long i;
29 double a = 0.0012;
30
31 for ( i = 0; i < n; i++ ) {
32 a += 0.01;
33 }
34 return a;
35}
int i
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 117 of file kufrin.c.

118{
119 int nthreads = 8, retval, i;
121 pthread_t *threads;
122 int quiet;
123
124 /* Set TESTS_QUIET variable */
125 quiet = tests_quiet( argc, argv );
126
127 if ( !quiet ) {
128 if ( argc > 1 ) {
129 int tmp = atoi( argv[1] );
130 if ( tmp >= 1 )
131 nthreads = tmp;
132 }
133 }
134
136 if ( retval != PAPI_VER_CURRENT ) {
137 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
138 }
139
140 retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self );
141 if ( retval != PAPI_OK ) {
142 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
143 }
144
146 if ( retval != PAPI_OK ) {
147 test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", retval );
148 }
149
150 if ((max_events = PAPI_get_cmp_opt(PAPI_MAX_MPX_CTRS,NULL,0)) <= 0) {
151 test_fail( __FILE__, __LINE__, "PAPI_get_cmp_opt", max_events );
152 }
153
154 if ((events = calloc(max_events,sizeof(int))) == NULL) {
155 test_fail( __FILE__, __LINE__, "calloc", PAPI_ESYS );
156 }
157
158 /* Fill up the event set with as many non-derived events as we can */
159
161 do {
162 if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
163 if ( info.count == 1 ) {
164 events[numevents++] = ( int ) info.event_code;
165 if (!quiet) printf( "Added %s\n", info.symbol );
166 } else {
167 if (!quiet) printf( "Skipping derived event %s\n", info.symbol );
168 }
169 }
170 } while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK )
171 && ( numevents < max_events ) );
172
173 if (!quiet) printf( "Found %d events\n", numevents );
174
175 if (numevents==0) {
176 test_skip(__FILE__,__LINE__,"No events found",0);
177 }
178
179 do_stuff( );
180
181 if (!quiet) printf( "Creating %d threads:\n", nthreads );
182
183 threads =
184 ( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) );
185 if ( threads == NULL ) {
186 free(events);
187 test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM );
188 }
189
190 /* Create the threads */
191 for ( i = 0; i < nthreads; i++ ) {
192 retval = pthread_create( &threads[i], NULL, thread, NULL );
193 if ( retval != 0 ) {
194 free(events);
195 free(threads);
196 test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
197 }
198 }
199
200 /* Wait for thread completion */
201 for ( i = 0; i < nthreads; i++ ) {
202 retval = pthread_join( threads[i], NULL );
203 if ( retval != 0 ) {
204 free(events);
205 free(threads);
206 test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS );
207 }
208 }
209
210 if (!quiet) printf( "Done." );
211
212 free(events);
213 free(threads);
214 test_pass( __FILE__ );
215
216 pthread_exit( NULL );
217
218 return 0;
219}
double tmp
Enumerate PAPI preset or native events.
Get component specific PAPI options.
Get the event's name and description info.
initialize the PAPI library.
Initialize multiplex support in the PAPI library.
Initialize thread support in the PAPI library.
void do_stuff(void)
Definition: do_loops.c:256
#define PAPI_MAX_MPX_CTRS
Definition: f90papi.h:172
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_ENOMEM
Definition: f90papi.h:16
static int numevents
Definition: kufrin.c:22
static int * events
Definition: kufrin.c:21
void * thread(void *arg)
Definition: kufrin.c:38
static int max_events
Definition: kufrin.c:23
#define PAPI_PRESET_MASK
@ PAPI_PRESET_ENUM_AVAIL
Definition: papi.h:490
unsigned long int pthread_t
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
if(file==NULL) goto out
int quiet
Definition: rapl_overflow.c:19
int
Definition: sde_internal.h:89
unsigned int count
Definition: papi.h:981
unsigned int event_code
Definition: papi.h:958
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ thread()

void * thread ( void *  arg)

Definition at line 38 of file kufrin.c.

39{
40 ( void ) arg; /*unused */
41 int eventset = PAPI_NULL;
42 long long *values;
43
44 int ret = PAPI_register_thread( );
45 if ( ret != PAPI_OK )
46 test_fail( __FILE__, __LINE__, "PAPI_register_thread", ret );
47 ret = PAPI_create_eventset( &eventset );
48 if ( ret != PAPI_OK )
49 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
50
51 values=calloc(max_events,sizeof(long long));
52
53 if (!TESTS_QUIET) printf( "Event set %d created\n", eventset );
54
55 /* In Component PAPI, EventSets must be assigned a component index
56 before you can fiddle with their internals.
57 0 is always the cpu component */
58 ret = PAPI_assign_eventset_component( eventset, 0 );
59 if ( ret != PAPI_OK ) {
60 free(values);
61 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", ret );
62 }
63
64 ret = PAPI_set_multiplex( eventset );
65 if ( ret == PAPI_ENOSUPP) {
66 free(values);
67 test_skip( __FILE__, __LINE__, "Multiplexing not supported", 1 );
68 }
69 else if ( ret != PAPI_OK ) {
70 free(values);
71 test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", ret );
72 }
73
74 ret = PAPI_add_events( eventset, events, numevents );
75 if ( ret < PAPI_OK ) {
76 free(values);
77 test_fail( __FILE__, __LINE__, "PAPI_add_events", ret );
78 }
79
80 ret = PAPI_start( eventset );
81 if ( ret != PAPI_OK ) {
82 free(values);
83 test_fail( __FILE__, __LINE__, "PAPI_start", ret );
84 }
85
86 do_stuff( );
87
88 ret = PAPI_stop( eventset, values );
89 if ( ret != PAPI_OK ) {
90 free(values);
91 test_fail( __FILE__, __LINE__, "PAPI_stop", ret );
92 }
93
94 ret = PAPI_cleanup_eventset( eventset );
95 if ( ret != PAPI_OK ) {
96 free(values);
97 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", ret );
98 }
99
100 ret = PAPI_destroy_eventset( &eventset );
101 if ( ret != PAPI_OK ) {
102 free(values);
103 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
104 }
105
106 ret = PAPI_unregister_thread( );
107 if ( ret != PAPI_OK ) {
108 free(values);
109 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
110 }
111
112 free(values);
113 return ( NULL );
114}
add multiple PAPI presets or native hardware events to an event set
Assign a component index to an existing but empty EventSet.
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Notify PAPI that a thread has 'appeared'.
Convert a standard event set to a multiplexed event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Notify PAPI that a thread has 'disappeared'.
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_ENOSUPP
Definition: f90papi.h:244
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int TESTS_QUIET
Definition: test_utils.c:18
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ events

int* events
static

Definition at line 21 of file kufrin.c.

◆ max_events

int max_events =0
static

Definition at line 23 of file kufrin.c.

◆ numevents

int numevents = 0
static

Definition at line 22 of file kufrin.c.