PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pthrtough.c
Go to the documentation of this file.
1 #include <pthread.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include "papi_test.h"
5 
6 #define NITER 1000
7 
8 void *
9 Thread( void *data )
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 }
31 
32 int
33 main( int argc, char *argv[] )
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:775
#define PAPI_NULL
Definition: fpapi.h:13
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
tests_quiet(argc, argv)
void
Definition: iozone.c:18627
#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:118
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define NITER
Definition: pthrtough.c:6
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
void * Thread(void *arg)
pthread_t
Definition: iozone.c:18557
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
#define PAPI_ESYS
Definition: fpapi.h:108
int PAPI_unregister_thread(void)
Definition: papi.c:239
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
long j
Definition: iozone.c:19135
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
pthread_attr_t attr
Definition: iozone.c:18466
int ncpu
Definition: papi.h:776