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

Go to the source code of this file.

Functions

voidThread (void *arg)
 
int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 120 of file zero_pthreads.c.

121 {
122  pthread_t e_th, f_th, g_th, h_th;
123  int flops1, flops2, flops3, flops4;
124  int retval, rc;
125  pthread_attr_t attr;
126  long long elapsed_us, elapsed_cyc;
127  int quiet;
128 
129  /* Set TESTS_QUIET variable */
130  quiet = tests_quiet( argc, argv );
131 
132  /* Init PAPI library */
134  if ( retval != PAPI_VER_CURRENT ) {
135  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
136  }
137 
139  if (!quiet) printf("Can't find PAPI_TOT_INS\n");
140  test_skip(__FILE__,__LINE__,"Event missing",1);
141  }
142 
144  if (!quiet) printf("Can't find PAPI_TOT_CYC\n");
145  test_skip(__FILE__,__LINE__,"Event missing",1);
146  }
147 
148  retval = PAPI_thread_init( ( unsigned long ( * )( void ) )
149  ( pthread_self ) );
150 
151  if ( retval != PAPI_OK ) {
152  if ( retval == PAPI_ECMP ) {
153  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
154  }
155  else {
156  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
157  }
158  }
159 
160  elapsed_us = PAPI_get_real_usec( );
161 
162  elapsed_cyc = PAPI_get_real_cyc( );
163 
164  pthread_attr_init( &attr );
165 #ifdef PTHREAD_CREATE_UNDETACHED
166  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
167 #endif
168 #ifdef PTHREAD_SCOPE_SYSTEM
169  retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
170  if ( retval != 0 )
171  test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
172 #endif
173 
174  flops1 = 1000000;
175  rc = pthread_create( &e_th, &attr, Thread, ( void * ) &flops1 );
176  if ( rc ) {
177  retval = PAPI_ESYS;
178  test_fail( __FILE__, __LINE__, "pthread_create", retval );
179  }
180  flops2 = 2000000;
181  rc = pthread_create( &f_th, &attr, Thread, ( void * ) &flops2 );
182  if ( rc ) {
183  retval = PAPI_ESYS;
184  test_fail( __FILE__, __LINE__, "pthread_create", retval );
185  }
186 
187  flops3 = 4000000;
188  rc = pthread_create( &g_th, &attr, Thread, ( void * ) &flops3 );
189  if ( rc ) {
190  retval = PAPI_ESYS;
191  test_fail( __FILE__, __LINE__, "pthread_create", retval );
192  }
193 
194  flops4 = 8000000;
195  rc = pthread_create( &h_th, &attr, Thread, ( void * ) &flops4 );
196  if ( rc ) {
197  retval = PAPI_ESYS;
198  test_fail( __FILE__, __LINE__, "pthread_create", retval );
199  }
200 
201  pthread_attr_destroy( &attr );
202  flops1 = 500000;
203  Thread( &flops1 );
204  pthread_join( h_th, NULL );
205  pthread_join( g_th, NULL );
206  pthread_join( f_th, NULL );
207  pthread_join( e_th, NULL );
208 
209  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
210  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
211 
212  if ( !quiet ) {
213  printf( "Master real usec : \t%lld\n", elapsed_us );
214  printf( "Master real cycles : \t%lld\n", elapsed_cyc );
215  }
216 
217  test_pass( __FILE__ );
218 
219  pthread_exit( NULL );
220 
221  return 0;
222 }
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
int rc
Definition: iozone.c:20281
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
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
long long elapsed_cyc
Definition: zero_fork.c:50
#define PAPI_ESYS
Definition: papi.h:255
#define PAPI_ECMP
Definition: papi.h:256
pthread_t
Definition: iozone.c:18557
int PAPI_query_event(int EventCode)
Definition: papi.c:684
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
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
static void * Thread(void *arg)
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:50
#define PAPI_VER_CURRENT
Definition: papi.h:225
pthread_attr_t attr
Definition: iozone.c:18466

Here is the call graph for this function:

void* Thread ( void arg)

Definition at line 41 of file zero_pthreads.c.

42 {
43  int retval, num_tests = 1;
44  int EventSet1 = PAPI_NULL;
45  int PAPI_event, mask1;
46  int num_events1;
47  long long **values;
48  long long elapsed_us, elapsed_cyc;
50 
51  retval = PAPI_register_thread( );
52  if ( retval != PAPI_OK ) {
53  test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
54  }
55 
56  if (!TESTS_QUIET) {
57  printf( "Thread %#x started\n", ( int ) pthread_self( ) );
58  }
59 
60  /* add PAPI_TOT_CYC and one of the events in
61  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
62  depending on the availability of the event
63  on the platform */
64  EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
65  if (!TESTS_QUIET) {
66  printf("Events %d\n",num_events1);
67  }
68  if (num_events1<2) {
69  test_fail( __FILE__, __LINE__, "Not enough events", retval );
70  }
71 
72  retval = PAPI_event_code_to_name( PAPI_event, event_name );
73  if ( retval != PAPI_OK ) {
74  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
75  }
76 
77  values = allocate_test_space( num_tests, num_events1 );
78 
79  elapsed_us = PAPI_get_real_usec( );
80  elapsed_cyc = PAPI_get_real_cyc( );
81 
82  retval = PAPI_start( EventSet1 );
83  if ( retval != PAPI_OK ) {
84  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
85  }
86 
87  do_flops( *( int * ) arg );
88 
89  retval = PAPI_stop( EventSet1, values[0] );
90  if ( retval != PAPI_OK ) {
91  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
92  }
93 
94  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
95  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
96 
97  remove_test_events( &EventSet1, mask1 );
98 
99  if ( !TESTS_QUIET ) {
100  printf( "Thread %#x %-12s : \t%lld\n", ( int ) pthread_self( ),
101  event_name, values[0][1] );
102  printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", (int) pthread_self(),
103  values[0][0] );
104  printf( "Thread %#x Real usec : \t%lld\n",
105  ( int ) pthread_self( ),
106  elapsed_us );
107  printf( "Thread %#x Real cycles : \t%lld\n", (int) pthread_self(),
108  elapsed_cyc );
109  }
110 
111  free_test_space( values, num_tests );
112 
113  retval = PAPI_unregister_thread( );
114  if ( retval != PAPI_OK )
115  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
116  return NULL;
117 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
int PAPI_event[2]
Definition: data_range.c:30
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
int PAPI_register_thread(void)
Definition: papi.c:208
return PAPI_OK
Definition: linux-nvml.c:497
long long elapsed_cyc
Definition: zero_fork.c:50
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:615
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
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
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:50
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int EventSet1
Definition: zero_fork.c:47

Here is the call graph for this function: