PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clockres_pthreads.c
Go to the documentation of this file.
1 #include <pthread.h>
2 #include "papi_test.h"
3 
4 
5 void *
6 pthread_main( void *arg )
7 {
8  ( void ) arg;
10  if ( retval != PAPI_OK ) {
11  test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
12  }
13 
14  clockcore( );
15 
16  retval = PAPI_unregister_thread( );
17  if ( retval != PAPI_OK ) {
18  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
19  }
20  return NULL;
21 }
22 
23 int
24 main( int argc, char **argv )
25 {
26  pthread_t t1, t2, t3, t4;
27  pthread_attr_t attr;
28  int retval;
29 
30  /* Set TESTS_QUIET variable */
31  tests_quiet( argc, argv );
32 
34  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
35  }
36 
37  retval = PAPI_thread_init( ( unsigned long ( * )(void) ) (pthread_self) );
38  if ( retval != PAPI_OK ) {
39  if ( retval == PAPI_ECMP ) {
40  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
41  }
42  else {
43  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
44  }
45  }
46 
47  if ( !TESTS_QUIET ) {
48  printf( "Test case: Clock latency and resolution.\n" );
49  printf( "Note: Virtual timers are proportional to # CPUs.\n" );
50  printf( "------------------------------------------------\n" );
51  }
52 
53  pthread_attr_init( &attr );
54 
55 #ifdef PTHREAD_CREATE_UNDETACHED
56  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
57 #endif
58 
59 #ifdef PTHREAD_SCOPE_SYSTEM
60  retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
61  if ( retval != 0 ) {
62  test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
63  }
64 #endif
65 
66  if (pthread_create( &t1, &attr, pthread_main, NULL )) {
67  test_fail(__FILE__, __LINE__, "cannot create thread", retval);
68  }
69 
70  if (pthread_create( &t2, &attr, pthread_main, NULL )) {
71  test_fail(__FILE__, __LINE__, "cannot create thread", retval);
72  }
73 
74  if (pthread_create( &t3, &attr, pthread_main, NULL )) {
75  test_fail(__FILE__, __LINE__, "cannot create thread", retval);
76  }
77 
78  if (pthread_create( &t4, &attr, pthread_main, NULL )) {
79  test_fail(__FILE__, __LINE__, "cannot create thread", retval);
80  }
81 
82  pthread_main( NULL );
83 
84  pthread_join( t1, NULL );
85  pthread_join( t2, NULL );
86  pthread_join( t3, NULL );
87  pthread_join( t4, NULL );
88 
89  test_pass( __FILE__, NULL, 0 );
90  exit( 0 );
91 }
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
int PAPI_register_thread(void)
Definition: papi.c:203
return PAPI_OK
Definition: linux-nvml.c:458
volatile double t2
tests_quiet(argc, argv)
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
volatile double t1
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
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
#define PAPI_ECMP
Definition: fpapi.h:109
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
pthread_t
Definition: iozone.c:18557
void * pthread_main(void *arg)
void clockcore(void)
Definition: clockcore.c:99
int PAPI_unregister_thread(void)
Definition: papi.c:239
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
pthread_attr_t attr
Definition: iozone.c:18466