PAPI  5.6.0.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 MAX_THREADS   256
 
#define EVENT   PAPI_TOT_CYC
 

Functions

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

Variables

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

Macro Definition Documentation

#define EVENT   PAPI_TOT_CYC

Definition at line 15 of file krentel_pthreads.c.

#define MAX_THREADS   256

Definition at line 5 of file krentel_pthreads.c.

Function Documentation

static void do_cycles ( long  num,
int  len 
)
static

Definition at line 71 of file krentel_pthreads.c.

72 {
73  struct timeval start, now;
74  double x, sum;
75 
76  gettimeofday( &start, NULL );
77 
78  for ( ;; ) {
79  sum = 1.0;
80  for ( x = 1.0; x < 250000.0; x += 1.0 )
81  sum += x;
82  if ( sum < 0.0 )
83  printf( "==>> SUM IS NEGATIVE !! <<==\n" );
84 
85  iter[num]++;
86 
87  gettimeofday( &now, NULL );
88  if ( now.tv_sec >= start.tv_sec + len )
89  break;
90  }
91 }
start
Definition: iozone.c:22736
static long iter[MAX_THREADS]
void int num
Definition: iozone.c:22151
int gettimeofday(void *ptr1, void *ptr2)
printf("\tTry: -i 0 -i 1 \n\n")
int x
Definition: fileop.c:78

Here is the call graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 156 of file krentel_pthreads.c.

157 {
158  pthread_t *td = NULL;
159  long n;
160  int quiet,retval;
161 
162  /* Set TESTS_QUIET variable */
163  quiet=tests_quiet( argc, argv );
164 
165  if ( argc < 2 || sscanf( argv[1], "%d", &program_time ) < 1 )
166  program_time = 6;
167  if ( argc < 3 || sscanf( argv[2], "%d", &threshold ) < 1 )
168  threshold = 20000000;
169  if ( argc < 4 || sscanf( argv[3], "%d", &num_threads ) < 1 )
170  num_threads = 3;
171 
172  td = malloc((num_threads+1) * sizeof(pthread_t));
173  if (!td) {
174  test_fail( __FILE__, __LINE__, "td malloc failed", 1 );
175  }
176 
177  if (!quiet) {
178  printf( "program_time = %d, threshold = %d, num_threads = %d\n\n",
180  }
181 
183  test_fail( __FILE__, __LINE__, "PAPI_library_init failed", 1 );
184 
185  /* Test to be sure we can add events */
186  retval = PAPI_query_event( EVENT );
187  if (retval!=PAPI_OK) {
188  if (!quiet) printf("Trouble finding event\n");
189  test_skip(__FILE__,__LINE__,"Event not available",1);
190  }
191 
192  if ( PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ) !=
193  PAPI_OK )
194  test_fail( __FILE__, __LINE__, "PAPI_thread_init failed", 1 );
195 
196  if ( pthread_key_create( &key, NULL ) != 0 )
197  test_fail( __FILE__, __LINE__, "pthread key create failed", 1 );
198 
199  gettimeofday( &start, NULL );
200 
201  for ( n = 1; n <= num_threads; n++ ) {
202  if ( pthread_create( &(td[n]), NULL, my_thread, ( void * ) n ) != 0 )
203  test_fail( __FILE__, __LINE__, "pthread create failed", 1 );
204  }
205 
206  my_thread( ( void * ) 0 );
207 
208  /* wait for all the threads */
209  for ( n = 1; n <= num_threads; n++ ) {
210  if ( pthread_join( td[n], NULL))
211  test_fail( __FILE__, __LINE__, "pthread join failed", 1 );
212  }
213 
214  free(td);
215 
216  if (!quiet) printf( "done\n" );
217 
218  test_pass( __FILE__ );
219 
220  return 0;
221 }
void test_pass(const char *filename)
Definition: test_utils.c:432
start
Definition: iozone.c:22736
return PAPI_OK
Definition: linux-nvml.c:497
static void * my_thread(void *v)
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
int PAPI_library_init(int version)
Definition: papi.c:500
static int program_time
#define EVENT
int quiet
Definition: rapl_overflow.c:18
free(dummyfile[xx])
static int num_threads
static pthread_key_t key
pthread_t
Definition: iozone.c:18557
static int threshold
int PAPI_query_event(int EventCode)
Definition: papi.c:684
int gettimeofday(void *ptr1, void *ptr2)
printf("\tTry: -i 0 -i 1 \n\n")
sscanf(mnc->m_child_port,"%d",&mc.m_child_port)
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225

Here is the call graph for this function:

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

Definition at line 30 of file krentel_pthreads.c.

31 {
32  ( void ) EventSet;
33  ( void ) pc;
34  ( void ) ovec;
35  ( void ) context;
36 
37  long num = ( long ) pthread_getspecific( key );
38 
39  if ( num < 0 || num > num_threads )
40  test_fail( __FILE__, __LINE__, "getspecific failed", 1 );
41  count[num]++;
42 }
int EventSet
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
static int num_threads
void int num
Definition: iozone.c:22151
static pthread_key_t key
long long
Definition: iozone.c:19827
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468

Here is the call graph for this function:

Here is the caller graph for this function:

static void* my_thread ( void v)
static

Definition at line 94 of file krentel_pthreads.c.

95 {
96  long num = ( long ) v;
97  int n;
98  int EventSet = PAPI_NULL;
99  long long value;
100 
101  int retval;
102 
103  retval = PAPI_register_thread( );
104  if ( retval != PAPI_OK ) {
105  test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
106  }
107  pthread_setspecific( key, v );
108 
109  count[num] = 0;
110  iter[num] = 0;
111  last[num] = start;
112 
113  retval = PAPI_create_eventset( &EventSet );
114  if ( retval != PAPI_OK ) {
115  test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", retval );
116  }
117 
118  retval = PAPI_add_event( EventSet, EVENT );
119  if (retval != PAPI_OK ) {
120  if (!TESTS_QUIET) printf("Trouble adding event\n");
121  test_fail( __FILE__, __LINE__, "PAPI_add_event failed", retval );
122  }
123 
124  if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK )
125  test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 );
126 
127  if ( PAPI_start( EventSet ) != PAPI_OK )
128  test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 );
129 
130  if (!TESTS_QUIET) printf( "launched timer in thread %ld\n", num );
131 
132  for ( n = 1; n <= program_time; n++ ) {
133  do_cycles( num, 1 );
134  print_rate( num );
135  }
136 
137  PAPI_stop( EventSet, &value );
138 
139  retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler);
140  if ( retval != PAPI_OK )
141  test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval );
142 
143  if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK )
144  test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 );
145 
146  if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK )
147  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 );
148 
149  if ( PAPI_unregister_thread( ) != PAPI_OK )
150  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 );
151 
152  return ( NULL );
153 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
start
Definition: iozone.c:22736
int PAPI_remove_event(int EventSet, int EventCode)
Definition: papi.c:1758
#define PAPI_NULL
Definition: papi.h:292
static void print_rate(long num)
int EventSet
int PAPI_register_thread(void)
Definition: papi.c:208
return PAPI_OK
Definition: linux-nvml.c:497
int count
Definition: iozone.c:22422
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4788
void double value
Definition: iozone.c:18781
static long iter[MAX_THREADS]
static int program_time
#define EVENT
static struct timeval last[MAX_THREADS]
void int num
Definition: iozone.c:22151
static pthread_key_t key
long long
Definition: iozone.c:19827
static void my_handler(int EventSet, void *pc, long long ovec, void *context)
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
static int threshold
static void do_cycles(int program_time)
Definition: fork_overflow.c:95
printf("\tTry: -i 0 -i 1 \n\n")
int PAPI_unregister_thread(void)
Definition: papi.c:244
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
int PAPI_start(int EventSet)
Definition: papi.c:2096
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

Here is the caller graph for this function:

static void print_rate ( long  num)
static

Definition at line 45 of file krentel_pthreads.c.

46 {
47  struct timeval now;
48  long st_secs;
49  double last_secs;
50 
51  gettimeofday( &now, NULL );
52  st_secs = now.tv_sec - start.tv_sec;
53  last_secs = ( double ) ( now.tv_sec - last[num].tv_sec )
54  + ( ( double ) ( now.tv_usec - last[num].tv_usec ) ) / 1000000.0;
55  if ( last_secs <= 0.001 )
56  last_secs = 0.001;
57 
58  if (!TESTS_QUIET) {
59  printf( "[%ld] time = %ld, count = %ld, iter = %ld, "
60  "rate = %.1f/Kiter\n",
61  num, st_secs, count[num], iter[num],
62  ( 1000.0 * ( double ) count[num] ) / ( double ) iter[num] );
63  }
64 
65  count[num] = 0;
66  iter[num] = 0;
67  last[num] = now;
68 }
start
Definition: iozone.c:22736
int count
Definition: iozone.c:22422
static double
Definition: fileop.c:1281
static long iter[MAX_THREADS]
static struct timeval last[MAX_THREADS]
void int num
Definition: iozone.c:22151
int gettimeofday(void *ptr1, void *ptr2)
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

long count[MAX_THREADS]
static

Definition at line 21 of file krentel_pthreads.c.

long iter[MAX_THREADS]
static

Definition at line 22 of file krentel_pthreads.c.

pthread_key_t key
static

Definition at line 25 of file krentel_pthreads.c.

struct timeval last[MAX_THREADS]
static

Definition at line 23 of file krentel_pthreads.c.

int num_threads = 3
static

Definition at line 19 of file krentel_pthreads.c.

int program_time = 5
static

Definition at line 17 of file krentel_pthreads.c.

struct timeval start
static

Definition at line 27 of file krentel_pthreads.c.

int threshold = 20000000
static

Definition at line 18 of file krentel_pthreads.c.