PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
examples/overflow_pthreads.c File Reference
Include dependency graph for examples/overflow_pthreads.c:

Go to the source code of this file.

Macros

#define THRESHOLD   200000
 
#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"
 
#define ERROR_RETURN(retval)   { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
 

Functions

void do_flops (int n)
 
void handler (int EventSet, void *address, long long overflow_vector, void *context)
 
voidThread (void *arg)
 
int main (int argc, char **argv)
 

Variables

int total = 0
 

Macro Definition Documentation

#define ERROR_RETURN (   retval)    { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Definition at line 26 of file examples/overflow_pthreads.c.

#define OVER_FMT   "handler(%d ) Overflow at %p! bit=%#llx \n"

Definition at line 25 of file examples/overflow_pthreads.c.

#define THRESHOLD   200000

Definition at line 24 of file examples/overflow_pthreads.c.

Function Documentation

void do_flops ( int  n)

Definition at line 31 of file examples/overflow_pthreads.c.

32 {
33  int i;
34  double c = 0.11;
35  double a = 0.5;
36  double b = 6.2;
37 
38  for (i=0; i < n; i++)
39  c += a * b;
40 }
double c
Definition: multiplex.c:22
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
int i
Definition: fileop.c:140
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
int n
Definition: mendes-alt.c:164
void handler ( int  EventSet,
void address,
long long  overflow_vector,
void context 
)

Definition at line 44 of file examples/overflow_pthreads.c.

45 {
46  fprintf(stderr, OVER_FMT, EventSet, address, overflow_vector);
47  total++;
48 }
int EventSet
static int total
Definition: rapl_overflow.c:5
#define OVER_FMT
int main ( int  argc,
char **  argv 
)

Definition at line 120 of file examples/overflow_pthreads.c.

121 {
122  pthread_t thread_one;
123  pthread_t thread_two;
124  int flops1, flops2;
125  int rc,retval;
126  pthread_attr_t attr;
127  long long elapsed_us, elapsed_cyc;
128 
129 
130  /* papi library initialization */
132  {
133  printf("Library initialization error! \n");
134  exit(1);
135  }
136 
137  /* thread initialization */
138  retval=PAPI_thread_init((unsigned long(*)(void))(pthread_self));
139  if (retval != PAPI_OK)
140  ERROR_RETURN(retval);
141 
142  /* return the number of microseconds since some arbitrary starting point */
143  elapsed_us = PAPI_get_real_usec();
144 
145  /* return the number of cycles since some arbitrary starting point */
146  elapsed_cyc = PAPI_get_real_cyc();
147 
148  /* pthread attribution init */
149  pthread_attr_init(&attr);
150  pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
151 
152  /* create the first thread */
153  flops1 = 1000000;
154  rc = pthread_create(&thread_one, &attr, Thread, (void *)&flops1);
155  if (rc)
156  ERROR_RETURN(rc);
157 
158  /* create the second thread */
159  flops2 = 4000000;
160  rc = pthread_create(&thread_two, &attr, Thread, (void *)&flops2);
161  if (rc)
162  ERROR_RETURN(rc);
163 
164  /* wait for the threads to finish */
165  pthread_attr_destroy(&attr);
166  pthread_join(thread_one, NULL);
167  pthread_join(thread_two, NULL);
168 
169  /* compute the elapsed cycles and microseconds */
170  elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;
171 
172  elapsed_us = PAPI_get_real_usec() - elapsed_us;
173 
174  printf("Master real usec : \t%lld\n", elapsed_us);
175  printf("Master real cycles : \t%lld\n", elapsed_cyc);
176 
177  /* clean up */
178  PAPI_shutdown();
179  exit(0);
180 }
return PAPI_OK
Definition: linux-nvml.c:458
#define printf
Definition: papi_test.h:125
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:118
int PAPI_library_init(int version)
Definition: papi.c:495
void PAPI_shutdown(void)
Definition: papi.c:4357
long long elapsed_cyc
Definition: zero_fork.c:43
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
void * Thread(void *arg)
#define ERROR_RETURN(retval)
pthread_t
Definition: iozone.c:18557
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
int rc
Definition: iozone.c:20281
long long PAPI_get_real_cyc(void)
Definition: papi.c:6091
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
void exit()
pthread_attr_t attr
Definition: iozone.c:18466

Here is the call graph for this function:

void* Thread ( void arg)

Definition at line 50 of file examples/overflow_pthreads.c.

51 {
52  int retval;
53  int EventSet1=PAPI_NULL;
54  long long values[2];
55  long long elapsed_us, elapsed_cyc;
56 
57  fprintf(stderr,"Thread %lx running PAPI\n",PAPI_thread_id());
58 
59  /* create the event set */
60  if ( (retval = PAPI_create_eventset(&EventSet1))!=PAPI_OK)
61  ERROR_RETURN(retval);
62 
63  /* query whether the event exists */
64  if ((retval=PAPI_query_event(PAPI_TOT_INS)) != PAPI_OK)
65  ERROR_RETURN(retval);
66  if ((retval=PAPI_query_event(PAPI_TOT_CYC)) != PAPI_OK)
67  ERROR_RETURN(retval);
68 
69  /* add events to the event set */
70  if ( (retval = PAPI_add_event(EventSet1, PAPI_TOT_INS))!= PAPI_OK)
71  ERROR_RETURN(retval);
72 
73  if ( (retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC)) != PAPI_OK)
74  ERROR_RETURN(retval);
75 
76  elapsed_us = PAPI_get_real_usec();
77 
78  elapsed_cyc = PAPI_get_real_cyc();
79 
80  retval = PAPI_overflow(EventSet1, PAPI_TOT_CYC, THRESHOLD, 0, handler);
81  if(retval !=PAPI_OK)
82  ERROR_RETURN(retval);
83 
84  /* start counting */
85  if((retval = PAPI_start(EventSet1))!=PAPI_OK)
86  ERROR_RETURN(retval);
87 
88  do_flops(*(int *)arg);
89 
90  if ((retval = PAPI_stop(EventSet1, values))!=PAPI_OK)
91  ERROR_RETURN(retval);
92 
93  elapsed_us = PAPI_get_real_usec() - elapsed_us;
94 
95  elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;
96 
97  /* disable overflowing */
98  retval = PAPI_overflow(EventSet1, PAPI_TOT_CYC, 0, 0, handler);
99  if(retval !=PAPI_OK)
100  ERROR_RETURN(retval);
101 
102  /* remove the event from the eventset */
103  retval = PAPI_remove_event(EventSet1, PAPI_TOT_INS);
104  if (retval != PAPI_OK)
105  ERROR_RETURN(retval);
106 
107  retval = PAPI_remove_event(EventSet1, PAPI_TOT_CYC);
108  if (retval != PAPI_OK)
109  ERROR_RETURN(retval);
110 
111  printf("Thread %#x PAPI_TOT_INS : \t%lld\n",(int)PAPI_thread_id(),
112  values[0]);
113  printf(" PAPI_TOT_CYC: \t%lld\n", values[1]);
114  printf(" Real usec : \t%lld\n", elapsed_us);
115  printf(" Real cycles : \t%lld\n", elapsed_cyc);
116 
117  pthread_exit(NULL);
118 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
#define PAPI_NULL
Definition: fpapi.h:13
unsigned long PAPI_thread_id(void)
Definition: papi.c:157
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1699
#define PAPI_TOT_INS
Definition: fpapi.h:185
return PAPI_OK
Definition: linux-nvml.c:458
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4668
#define printf
Definition: papi_test.h:125
#define PAPI_TOT_CYC
Definition: fpapi.h:194
long long elapsed_cyc
Definition: zero_fork.c:43
#define ERROR_RETURN(retval)
void handler(int EventSet, void *address, long long overflow_vector, void *context)
Definition: rapl_overflow.c:16
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:696
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
#define THRESHOLD
long long PAPI_get_real_cyc(void)
Definition: papi.c:6091
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
int EventSet1
Definition: zero_fork.c:40

Here is the call graph for this function:

Variable Documentation

int total = 0

Definition at line 29 of file examples/overflow_pthreads.c.