PAPI 7.1.0.0
Loading...
Searching...
No Matches
pthrtough.c File Reference
Include dependency graph for pthrtough.c:

Go to the source code of this file.

Macros

#define NITER   1000
 

Functions

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

Macro Definition Documentation

◆ NITER

#define NITER   1000

Definition at line 9 of file pthrtough.c.

Function Documentation

◆ main()

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 free(th);
90 test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
91 }
92 }
93
94 for ( j = 0; j < nthr; j++ ) {
95 pthread_join( th[j], NULL );
96 }
97
98 free(th);
99 test_pass( __FILE__ );
100
101 return 0;
102
103}
get information about the system hardware
initialize the PAPI library.
Initialize thread support in the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ESYS
Definition: f90papi.h:136
int TESTS_QUIET
Definition: test_utils.c:18
unsigned long int pthread_t
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
#define NITER
Definition: pthrtough.c:9
void * Thread(void *data)
Definition: pthrtough.c:12
Hardware info structure.
Definition: papi.h:774
int ncpu
Definition: papi.h:775
Here is the call graph for this function:

◆ Thread()

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}
int i
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Notify PAPI that a thread has 'appeared'.
Notify PAPI that a thread has 'disappeared'.
#define PAPI_NULL
Definition: f90papi.h:78
Here is the call graph for this function:
Here is the caller graph for this function: