PAPI 7.1.0.0
Loading...
Searching...
No Matches
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)
 
void * Thread (void *arg)
 
int main (int argc, char **argv)
 

Variables

int total = 0
 

Macro Definition Documentation

◆ ERROR_RETURN

#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.

◆ OVER_FMT

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

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

◆ THRESHOLD

#define THRESHOLD   200000

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

Function Documentation

◆ do_flops()

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}
int i
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
Here is the caller graph for this function:

◆ handler()

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}
#define OVER_FMT
static int EventSet
Definition: init_fini.c:8
FILE * stderr
Here is the caller graph for this function:

◆ main()

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)
141
142 /* return the number of microseconds since some arbitrary starting point */
144
145 /* return the number of cycles since some arbitrary starting point */
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)
157
158 /* create the second thread */
159 flops2 = 4000000;
160 rc = pthread_create(&thread_two, &attr, Thread, (void *)&flops2);
161 if (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 */
171
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 */
179 exit(0);
180}
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
initialize the PAPI library.
Finish using PAPI and free all related resources.
Initialize thread support in the PAPI library.
#define ERROR_RETURN(retval)
void * Thread(void *arg)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
unsigned long int pthread_t
rc
Definition: pscanf.h:23
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ Thread()

void * Thread ( void *  arg)

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

51{
52 int retval;
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 */
62
63 /* query whether the event exists */
68
69 /* add events to the event set */
72
75
77
79
81 if(retval !=PAPI_OK)
83
84 /* start counting */
87
88 do_flops(*(int *)arg);
89
92
94
96
97 /* disable overflowing */
99 if(retval !=PAPI_OK)
101
102 /* remove the event from the eventset */
104 if (retval != PAPI_OK)
106
108 if (retval != PAPI_OK)
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}
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Set up an event set to begin registering overflows.
Query if PAPI event exists.
removes a hardware event from a PAPI event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Get the thread identifier of the current thread.
void do_flops(int n)
#define THRESHOLD
void handler(int EventSet, void *address, long long overflow_vector, void *context)
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_TOT_INS
Definition: f90papi.h:317
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int EventSet1
Definition: zero_fork.c:47
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ total

int total = 0

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