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

Go to the source code of this file.

Macros

#define NITER   2000
 

Functions

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

Macro Definition Documentation

◆ NITER

#define NITER   2000

Definition at line 9 of file pthrtough2.c.

Function Documentation

◆ main()

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

Definition at line 35 of file pthrtough2.c.

36{
37 int j;
38 pthread_t *th = NULL;
39 pthread_attr_t attr;
40 int ret;
41 long nthr;
42
43 tests_quiet( argc, argv ); /*Set TESTS_QUIET variable */
44
46 if ( ret != PAPI_VER_CURRENT )
47 test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
48
49 if ( ( ret =
50 PAPI_thread_init( ( unsigned
51 long ( * )( void ) ) ( pthread_self ) ) ) !=
52 PAPI_OK )
53 test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
54
55 pthread_attr_init( &attr );
56#ifdef PTHREAD_CREATE_UNDETACHED
57 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
58#endif
59#ifdef PTHREAD_SCOPE_SYSTEM
60 ret = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
61 if ( ret != 0 )
62 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", ret );
63
64#endif
65
66 nthr = NITER;
67
68 if ( !TESTS_QUIET ) {
69 printf( "Creating %d threads for %d iterations each of:\n",
70 ( int ) nthr, 1 );
71 printf( "\tregister\n" );
72 printf( "\tcreate_eventset\n" );
73 printf( "\tdestroy_eventset\n" );
74 printf( "\tunregister\n" );
75 }
76 th = ( pthread_t * ) malloc( ( size_t ) nthr * sizeof ( pthread_t ) );
77 if ( th == NULL )
78 test_fail( __FILE__, __LINE__, "malloc", PAPI_ESYS );
79
80 for ( j = 0; j < nthr; j++ ) {
81 ret = pthread_create( &th[j], &attr, &Thread, NULL );
82 if ( ret ) {
83 printf( "Failed to create thread: %d\n", j );
84 if ( j < 10 ) {
85 free(th);
86 test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS );
87 }
88 printf( "Continuing test with %d threads.\n", j - 1 );
89 nthr = j - 1;
90 th = ( pthread_t * ) realloc( th,
91 ( size_t ) nthr *
92 sizeof ( pthread_t ) );
93 break;
94 }
95 }
96
97 for ( j = 0; j < nthr; j++ ) {
98 pthread_join( th[j], NULL );
99 }
100
101 free(th);
102 test_pass( __FILE__ );
103
104 return 0;
105}
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: pthrtough2.c:9
void * Thread(void *data)
Definition: pthrtough2.c:12
Here is the call graph for this function:

◆ Thread()

void * Thread ( void *  data)

Definition at line 12 of file pthrtough2.c.

13{
14 int ret, evtset;
15
16 ( void ) data;
17
18 if ( ( ret = PAPI_register_thread( ) ) != PAPI_OK )
19 test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret );
20
21 evtset = PAPI_NULL;
22 if ( ( ret = PAPI_create_eventset( &evtset ) ) != PAPI_OK )
23 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
24
25 if ( ( ret = PAPI_destroy_eventset( &evtset ) ) != PAPI_OK )
26 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret );
27
28 if ( ( ret = PAPI_unregister_thread( ) ) != PAPI_OK )
29 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret );
30
31 return ( NULL );
32}
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: