Go to the source code of this file.
Define Documentation
| #define OVER_FMT "handler(%d ) Overflow at %p! bit=0x%llx \n" |
Function Documentation
| void handler |
( |
int |
EventSet, |
|
|
void * |
address, |
|
|
long long |
overflow_vector, |
|
|
void * |
context |
|
) |
| |
| int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 120 of file examples/overflow_pthreads.c.
{
pthread_t thread_one;
pthread_t thread_two;
int flops1, flops2;
int rc,retval;
pthread_attr_t attr;
long long elapsed_us, elapsed_cyc;
if ((retval=PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT)
{
printf("Library initialization error! \n");
exit(1);
}
retval=PAPI_thread_init((unsigned long(*)(void))(pthread_self));
if (retval != PAPI_OK)
ERROR_RETURN(retval);
elapsed_us = PAPI_get_real_usec();
elapsed_cyc = PAPI_get_real_cyc();
pthread_attr_init(&attr);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
flops1 = 1000000;
rc = pthread_create(&thread_one, &attr, Thread, (void *)&flops1);
if (rc)
ERROR_RETURN(rc);
flops2 = 4000000;
rc = pthread_create(&thread_two, &attr, Thread, (void *)&flops2);
if (rc)
ERROR_RETURN(rc);
pthread_attr_destroy(&attr);
pthread_join(thread_one, NULL);
pthread_join(thread_two, NULL);
elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;
elapsed_us = PAPI_get_real_usec() - elapsed_us;
printf("Master real usec : \t%lld\n", elapsed_us);
printf("Master real cycles : \t%lld\n", elapsed_cyc);
PAPI_shutdown();
exit(0);
}
Definition at line 50 of file examples/overflow_pthreads.c.
{
int retval;
int EventSet1=PAPI_NULL;
long long values[2];
long long elapsed_us, elapsed_cyc;
fprintf(stderr,"Thread %lx running PAPI\n",PAPI_thread_id());
if ( (retval = PAPI_create_eventset(&EventSet1))!=PAPI_OK)
ERROR_RETURN(retval);
if ((retval=PAPI_query_event(PAPI_TOT_INS)) != PAPI_OK)
ERROR_RETURN(retval);
if ((retval=PAPI_query_event(PAPI_TOT_CYC)) != PAPI_OK)
ERROR_RETURN(retval);
if ( (retval = PAPI_add_event(EventSet1, PAPI_TOT_INS))!= PAPI_OK)
ERROR_RETURN(retval);
if ( (retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC)) != PAPI_OK)
ERROR_RETURN(retval);
elapsed_us = PAPI_get_real_usec();
elapsed_cyc = PAPI_get_real_cyc();
retval = PAPI_overflow(EventSet1, PAPI_TOT_CYC, THRESHOLD, 0, handler);
if(retval !=PAPI_OK)
ERROR_RETURN(retval);
if((retval = PAPI_start(EventSet1))!=PAPI_OK)
ERROR_RETURN(retval);
do_flops(*(int *)arg);
if ((retval = PAPI_stop(EventSet1, values))!=PAPI_OK)
ERROR_RETURN(retval);
elapsed_us = PAPI_get_real_usec() - elapsed_us;
elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc;
retval = PAPI_overflow(EventSet1, PAPI_TOT_CYC, 0, 0, handler);
if(retval !=PAPI_OK)
ERROR_RETURN(retval);
retval = PAPI_remove_event(EventSet1, PAPI_TOT_INS);
if (retval != PAPI_OK)
ERROR_RETURN(retval);
retval = PAPI_remove_event(EventSet1, PAPI_TOT_CYC);
if (retval != PAPI_OK)
ERROR_RETURN(retval);
printf("Thread 0x%x PAPI_TOT_INS : \t%lld\n",(int)PAPI_thread_id(),
values[0]);
printf(" PAPI_TOT_CYC: \t%lld\n", values[1]);
printf(" Real usec : \t%lld\n", elapsed_us);
printf(" Real cycles : \t%lld\n", elapsed_cyc);
pthread_exit(NULL);
}
Variable Documentation