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

Go to the source code of this file.

Macros

#define EVENT   PAPI_TOT_CYC
 

Functions

void my_handler (int EventSet, void *pc, long long ovec, void *context)
 
void print_rate (long num)
 
void do_cycles (long num, int len)
 
void launch_timer (int *EventSet)
 
voidmy_thread (void *v)
 
int main (int argc, char **argv)
 

Variables

int program_time = 5
 
int threshold = 20000000
 
int num_threads = 3
 
long count [MAX_THREADS]
 
long iter [MAX_THREADS]
 
struct timeval last [MAX_THREADS]
 
pthread_key_t key
 
struct timeval start
 

Macro Definition Documentation

#define EVENT   PAPI_TOT_CYC

Definition at line 9 of file krentel_pthreads.c.

Function Documentation

void do_cycles ( long  num,
int  len 
)

Definition at line 63 of file krentel_pthreads.c.

64 {
65  struct timeval start, now;
66  double x, sum;
67 
68  gettimeofday( &start, NULL );
69 
70  for ( ;; ) {
71  sum = 1.0;
72  for ( x = 1.0; x < 250000.0; x += 1.0 )
73  sum += x;
74  if ( sum < 0.0 )
75  printf( "==>> SUM IS NEGATIVE !! <<==\n" );
76 
77  iter[num]++;
78 
79  gettimeofday( &now, NULL );
80  if ( now.tv_sec >= start.tv_sec + len )
81  break;
82  }
83 }
start
Definition: iozone.c:22736
#define printf
Definition: papi_test.h:125
long iter[MAX_THREADS]
void int num
Definition: iozone.c:22151
int x
Definition: fileop.c:78
void launch_timer ( int EventSet)

Definition at line 86 of file krentel_pthreads.c.

87 {
89  test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 );
90 
91  if ( PAPI_add_event( *EventSet, EVENT ) != PAPI_OK )
92  test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 );
93 
95  PAPI_OK )
96  test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 );
97 
98  if ( PAPI_start( *EventSet ) != PAPI_OK )
99  test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 );
100 }
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1604
void my_handler(int EventSet, void *pc, long long ovec, void *context)
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
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
#define EVENT
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int threshold
int EventSet
int PAPI_start(int EventSet)
Definition: papi.c:2026

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 137 of file krentel_pthreads.c.

138 {
139  pthread_t td;
140  long n;
141 
142  tests_quiet( argc, argv ); /*Set TESTS_QUIET variable */
143 
144  if ( argc < 2 || sscanf( argv[1], "%d", &program_time ) < 1 )
145  program_time = 6;
146  if ( argc < 3 || sscanf( argv[2], "%d", &threshold ) < 1 )
147  threshold = 20000000;
148  if ( argc < 4 || sscanf( argv[3], "%d", &num_threads ) < 1 )
149  num_threads = 3;
150 
151  printf( "program_time = %d, threshold = %d, num_threads = %d\n\n",
153 
155  test_fail( __FILE__, __LINE__, "PAPI_library_init failed", 1 );
156 
157  if ( PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ) !=
158  PAPI_OK )
159  test_fail( __FILE__, __LINE__, "PAPI_thread_init failed", 1 );
160 
161  if ( pthread_key_create( &key, NULL ) != 0 )
162  test_fail( __FILE__, __LINE__, "pthread key create failed", 1 );
163 
164  gettimeofday( &start, NULL );
165 
166  for ( n = 1; n <= num_threads; n++ ) {
167  if ( pthread_create( &td, NULL, my_thread, ( void * ) n ) != 0 )
168  test_fail( __FILE__, __LINE__, "pthread create failed", 1 );
169  }
170 
171  my_thread( ( void * ) 0 );
172 
173  printf( "done\n" );
174 
175  test_pass( __FILE__, NULL, 0 );
176  pthread_exit( NULL );
177  return ( 0 );
178 }
start
Definition: iozone.c:22736
void * my_thread(void *v)
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:118
int PAPI_library_init(int version)
Definition: papi.c:495
int program_time
int num_threads
pthread_key_t key
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
pthread_t
Definition: iozone.c:18557
int threshold
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
int n
Definition: mendes-alt.c:164

Here is the call graph for this function:

void my_handler ( int  EventSet,
void pc,
long long  ovec,
void context 
)

Definition at line 24 of file krentel_pthreads.c.

25 {
26  ( void ) EventSet;
27  ( void ) pc;
28  ( void ) ovec;
29  ( void ) context;
30 
31  long num = ( long ) pthread_getspecific( key );
32 
33  if ( num < 0 || num > num_threads )
34  test_fail( __FILE__, __LINE__, "getspecific failed", 1 );
35  count[num]++;
36 }
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int num_threads
void int num
Definition: iozone.c:22151
pthread_key_t key
long long
Definition: iozone.c:19827
int EventSet

Here is the call graph for this function:

void* my_thread ( void v)

Definition at line 103 of file krentel_pthreads.c.

104 {
105  long num = ( long ) v;
106  int n;
107  int EventSet = PAPI_NULL;
108  long long value;
109 
110  int retval = PAPI_register_thread( );
111  if ( retval != PAPI_OK )
112  test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
113  pthread_setspecific( key, v );
114 
115  count[num] = 0;
116  iter[num] = 0;
117  last[num] = start;
118 
119  launch_timer( &EventSet );
120  printf( "launched timer in thread %ld\n", num );
121 
122  for ( n = 1; n <= program_time; n++ ) {
123  do_cycles( num, 1 );
124  print_rate( num );
125  }
126 
127  PAPI_stop( EventSet, &value );
128  PAPI_remove_event( EventSet, EVENT );
129  PAPI_destroy_eventset( &EventSet );
130  retval = PAPI_unregister_thread( );
131  if ( retval != PAPI_OK )
132  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
133  return ( NULL );
134 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
void do_cycles(int program_time)
#define PAPI_NULL
Definition: fpapi.h:13
start
Definition: iozone.c:22736
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1699
int PAPI_register_thread(void)
Definition: papi.c:203
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
#define printf
Definition: papi_test.h:125
void double value
Definition: iozone.c:18781
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
long iter[MAX_THREADS]
void launch_timer(int *EventSet)
int program_time
#define EVENT
void int num
Definition: iozone.c:22151
pthread_key_t key
long long
Definition: iozone.c:19827
static struct temp_event * last
int EventSet
int PAPI_unregister_thread(void)
Definition: papi.c:239
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1944
ssize_t retval
Definition: libasync.c:338
void print_rate(char *str)
int n
Definition: mendes-alt.c:164

Here is the call graph for this function:

Here is the caller graph for this function:

void print_rate ( long  num)

Definition at line 39 of file krentel_pthreads.c.

40 {
41  struct timeval now;
42  long st_secs;
43  double last_secs;
44 
45  gettimeofday( &now, NULL );
46  st_secs = now.tv_sec - start.tv_sec;
47  last_secs = ( double ) ( now.tv_sec - last[num].tv_sec )
48  + ( ( double ) ( now.tv_usec - last[num].tv_usec ) ) / 1000000.0;
49  if ( last_secs <= 0.001 )
50  last_secs = 0.001;
51 
52  printf( "[%ld] time = %ld, count = %ld, iter = %ld, "
53  "rate = %.1f/Kiter\n",
54  num, st_secs, count[num], iter[num],
55  ( 1000.0 * ( double ) count[num] ) / ( double ) iter[num] );
56 
57  count[num] = 0;
58  iter[num] = 0;
59  last[num] = now;
60 }
start
Definition: iozone.c:22736
int count
Definition: iozone.c:22422
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
long iter[MAX_THREADS]
void int num
Definition: iozone.c:22151
static struct temp_event * last

Variable Documentation

long count[MAX_THREADS]

Definition at line 15 of file krentel_pthreads.c.

Definition at line 16 of file krentel_pthreads.c.

pthread_key_t key

Definition at line 19 of file krentel_pthreads.c.

struct timeval last[MAX_THREADS]

Definition at line 17 of file krentel_pthreads.c.

int num_threads = 3

Definition at line 13 of file krentel_pthreads.c.

int program_time = 5

Definition at line 11 of file krentel_pthreads.c.

struct timeval start

Definition at line 21 of file krentel_pthreads.c.

int threshold = 20000000

Definition at line 12 of file krentel_pthreads.c.