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

Go to the source code of this file.

Macros

#define NITER   1000
 

Functions

voidThread (void *data)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

#define NITER   1000

Definition at line 9 of file pthrtough.c.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 36 of file pthrtough.c.

37 {
38  int j;
39  pthread_t *th = NULL;
40  pthread_attr_t attr;
41  int ret;
42  long nthr;
43  const PAPI_hw_info_t *hwinfo;
44 
45  tests_quiet( argc, argv ); /*Set TESTS_QUIET variable */
46 
48  if ( ret != PAPI_VER_CURRENT )
49  test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
50 
51  if ( ( ret =
52  PAPI_thread_init( ( unsigned
53  long ( * )( void ) ) ( pthread_self ) ) ) !=
54  PAPI_OK )
55  test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
56 
57  pthread_attr_init( &attr );
58 #ifdef PTHREAD_CREATE_UNDETACHED
59  pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
60 #endif
61 #ifdef PTHREAD_SCOPE_SYSTEM
62  ret=pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
63  if ( ret != 0 )
64  test_skip( __FILE__, __LINE__, "pthread_attr_setscope", ret );
65 
66 #endif
67 
68  if ( ( hwinfo = PAPI_get_hardware_info( ) ) == NULL )
69  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
70 
71  nthr = hwinfo->ncpu;
72 
73  if ( !TESTS_QUIET ) {
74  printf( "Creating %ld threads for %d iterations each of:\n", nthr,
75  NITER );
76  printf( "\tregister\n" );
77  printf( "\tcreate_eventset\n" );
78  printf( "\tdestroy_eventset\n" );
79  printf( "\tunregister\n" );
80  }
81 
82  th = ( pthread_t * ) malloc( ( size_t ) nthr * sizeof ( pthread_t ) );
83  if ( th == NULL )
84  test_fail( __FILE__, __LINE__, "malloc", PAPI_ESYS );
85 
86  for ( j = 0; j < nthr; j++ ) {
87  ret = pthread_create( &th[j], &attr, &Thread, NULL );
88  if ( ret )
89  test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
90  }
91 
92  for ( j = 0; j < nthr; j++ ) {
93  pthread_join( th[j], NULL );
94  }
95 
96  test_pass( __FILE__ );
97 
98  return 0;
99 
100 }
void test_pass(const char *filename)
Definition: test_utils.c:432
Hardware info structure.
Definition: papi.h:780
return PAPI_OK
Definition: linux-nvml.c:497
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
long long ret
Definition: iozone.c:1346
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
#define PAPI_ESYS
Definition: papi.h:255
#define NITER
Definition: pthrtough.c:9
pthread_t
Definition: iozone.c:18557
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
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 j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
#define PAPI_VER_CURRENT
Definition: papi.h:225
pthread_attr_t attr
Definition: iozone.c:18466
int ncpu
Definition: papi.h:781

Here is the call graph for this function:

void* Thread ( void data)

Definition at line 12 of file pthrtough.c.

13 {
14  int i, ret, evtset;
15 
16  ( void ) data;
17 
18  for ( i = 0; i < NITER; i++ ) {
19  if ( ( ret = PAPI_register_thread( ) ) != PAPI_OK )
20  test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
21 
22  evtset = PAPI_NULL;
23  if ( ( ret = PAPI_create_eventset( &evtset ) ) != PAPI_OK )
24  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
25 
26  if ( ( ret = PAPI_destroy_eventset( &evtset ) ) != PAPI_OK )
27  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
28 
29  if ( ( ret = PAPI_unregister_thread( ) ) != PAPI_OK )
30  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
31  }
32  return ( NULL );
33 }
#define PAPI_NULL
Definition: papi.h:292
int PAPI_register_thread(void)
Definition: papi.c:208
return PAPI_OK
Definition: linux-nvml.c:497
void
Definition: iozone.c:18627
long long ret
Definition: iozone.c:1346
int i
Definition: fileop.c:140
#define NITER
Definition: pthrtough.c:9
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
int PAPI_unregister_thread(void)
Definition: papi.c:244
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

Here is the call graph for this function: