13#define MAX_THREADS 256
23#define EVENT PAPI_TOT_CYC
45 long num = (
long ) pthread_getspecific(
key );
48 test_fail( __FILE__, __LINE__,
"getspecific failed", 1 );
59 gettimeofday( &now, NULL );
63 if ( last_secs <= 0.001 )
67 printf(
"[%ld] time = %ld, count = %ld, iter = %ld, "
68 "rate = %.1f/Kiter\n",
70 ( 1000.0 * (
double )
count[num] ) / (
double )
iter[num] );
84 gettimeofday( &
start, NULL );
88 for (
x = 1.0;
x < 250000.0;
x += 1.0 )
91 printf(
"==>> SUM IS NEGATIVE !! <<==\n" );
95 gettimeofday( &now, NULL );
104 long num = (
long ) v;
116 pthread_setspecific(
key, v );
124 test_fail( __FILE__, __LINE__,
"PAPI_create_eventset failed",
retval );
129 if (!
TESTS_QUIET) printf(
"Trouble creating event name\n");
130 test_fail( __FILE__, __LINE__,
"PAPI_event_name_to_code failed",
retval );
135 if (!
TESTS_QUIET) printf(
"Trouble adding event\n");
140 test_fail( __FILE__, __LINE__,
"PAPI_overflow failed", 1 );
143 test_fail( __FILE__, __LINE__,
"PAPI_start failed", 1 );
145 if (!
TESTS_QUIET) printf(
"launched timer in thread %ld\n", num );
156 test_fail( __FILE__, __LINE__,
"PAPI_overflow failed to reset the overflow handler",
retval );
159 test_fail( __FILE__, __LINE__,
"PAPI_remove_event", 1 );
162 test_fail( __FILE__, __LINE__,
"PAPI_destroy_eventset", 1 );
165 test_fail( __FILE__, __LINE__,
"PAPI_unregister_thread", 1 );
180 if ( argc < 2 || sscanf( argv[1],
"%d", &
program_time ) < 1 )
182 if ( argc < 3 || sscanf( argv[2],
"%d", &
threshold ) < 1 )
184 if ( argc < 4 || sscanf( argv[3],
"%d", &
num_threads ) < 1 )
189 test_fail( __FILE__, __LINE__,
"td malloc failed", 1 );
193 printf(
"program_time = %d, threshold = %d, num_threads = %d\n\n",
198 test_fail( __FILE__, __LINE__,
"PAPI_library_init failed", 1 );
203 if (!
quiet) printf(
"Trouble finding event\n");
204 test_skip(__FILE__,__LINE__,
"Event not available",1);
207 if (
PAPI_thread_init( (
unsigned long ( * )(
void ) ) ( pthread_self ) ) !=
209 test_fail( __FILE__, __LINE__,
"PAPI_thread_init failed", 1 );
211 if ( pthread_key_create( &
key, NULL ) != 0 )
212 test_fail( __FILE__, __LINE__,
"pthread key create failed", 1 );
214 gettimeofday( &
start, NULL );
217 if ( pthread_create( &(td[n]), NULL,
my_thread, (
void * ) n ) != 0 )
218 test_fail( __FILE__, __LINE__,
"pthread create failed", 1 );
225 if ( pthread_join( td[n], NULL))
226 test_fail( __FILE__, __LINE__,
"pthread join failed", 1 );
231 if (!
quiet) printf(
"done\n" );
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
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.
Initialize thread support in the PAPI library.
int PAPI_register_thread(void)
int PAPI_unregister_thread(void)
static long iter[MAX_THREADS]
static void * my_thread(void *v)
static long count[MAX_THREADS]
static struct timeval last[MAX_THREADS]
static void print_rate(long num)
static struct timeval start
static void my_handler(int EventSet, void *pc, long long ovec, void *context)
static void do_cycles(long num, int len)
Return codes and api definitions.
unsigned long int pthread_t
unsigned int pthread_key_t
int tests_quiet(int argc, char **argv)
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
void PAPI_NORETURN test_pass(const char *filename)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)