PAPI  5.4.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 6 of file pthrtough.c.

Function Documentation

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

Definition at line 33 of file pthrtough.c.

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

Here is the call graph for this function:

void* Thread ( void data)

Definition at line 9 of file pthrtough.c.

10 {
11  int i, ret, evtset;
12 
13  ( void ) data;
14 
15  for ( i = 0; i < NITER; i++ ) {
16  if ( ( ret = PAPI_register_thread( ) ) != PAPI_OK )
17  test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
18 
19  evtset = PAPI_NULL;
20  if ( ( ret = PAPI_create_eventset( &evtset ) ) != PAPI_OK )
21  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
22 
23  if ( ( ret = PAPI_destroy_eventset( &evtset ) ) != PAPI_OK )
24  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
25 
26  if ( ( ret = PAPI_unregister_thread( ) ) != PAPI_OK )
27  test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
28  }
29  return ( NULL );
30 }
#define PAPI_NULL
Definition: papi.h:290
int PAPI_register_thread(void)
Definition: papi.c:205
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
long long ret
Definition: iozone.c:1346
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int i
Definition: fileop.c:140
#define NITER
Definition: pthrtough.c:6
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1424
int PAPI_unregister_thread(void)
Definition: papi.c:241
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1971

Here is the call graph for this function: