PAPI  5.7.0.0
zero_pthreads.c File Reference
Include dependency graph for zero_pthreads.c:

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

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 
161 
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 
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 }
#define PAPI_OK
Definition: fpapi.h:105
rc
Definition: pscanf.h:23
void test_pass(const char *filename)
Definition: test_utils.c:432
unsigned long int pthread_t
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
#define PAPI_ECMP
Definition: fpapi.h:109
#define PAPI_ESYS
Definition: fpapi.h:108
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_TOT_INS
Definition: fpapi.h:186
int quiet
Definition: rapl_overflow.c:18
long long elapsed_cyc
Definition: zero_fork.c:50
int PAPI_query_event(int EventCode)
Definition: papi.c:684
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void * Thread(void *arg)
Definition: zero_pthreads.c:41
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
#define PAPI_TOT_CYC
Definition: fpapi.h:195
long long elapsed_us
Definition: zero_fork.c:50
Here is the call graph for this function:

◆ Thread()

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 
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 */
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 
73  if ( retval != PAPI_OK ) {
74  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
75  }
76 
78 
81 
83  if ( retval != PAPI_OK ) {
84  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
85  }
86 
87  do_flops( *( int * ) arg );
88 
90  if ( retval != PAPI_OK ) {
91  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
92  }
93 
96 
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 
112 
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
#define PAPI_OK
Definition: fpapi.h:105
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
int num_events1
Definition: zero_fork.c:49
int PAPI_register_thread(void)
Definition: papi.c:208
int retval
Definition: zero_fork.c:53
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:617
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
#define PAPI_NULL
Definition: fpapi.h:13
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
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
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
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
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
Here is the call graph for this function:
Here is the caller graph for this function: