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

Go to the source code of this file.

Functions

void * Thread (void *arg)
 
int main (int argc, char **argv)
 

Variables

static volatile int processing = 1
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 91 of file thrspecific.c.

92{
93 pthread_t e_th, f_th, g_th, h_th;
94 int flops1, flops2, flops3, flops4, flops5;
95 int retval, rc;
96 pthread_attr_t attr;
97 int quiet;
98
99 /* Set TESTS_QUIET variable */
100 quiet = tests_quiet( argc, argv );
101
102 if (!quiet) printf("Testing threads\n");
103
105 if ( retval != PAPI_VER_CURRENT ) {
106 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
107 }
108
109 retval = PAPI_thread_init( ( unsigned long ( * )( void ) )
110 ( pthread_self ) );
111 if ( retval != PAPI_OK ) {
112 if ( retval == PAPI_ECMP ) {
113 test_skip( __FILE__, __LINE__,
114 "PAPI_thread_init", retval );
115 }
116 else {
117 test_fail( __FILE__, __LINE__,
118 "PAPI_thread_init", retval );
119 }
120 }
121
122 pthread_attr_init( &attr );
123
124#ifdef PTHREAD_CREATE_UNDETACHED
125 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
126#endif
127
128#ifdef PTHREAD_SCOPE_SYSTEM
129 retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
130 if ( retval != 0 ) {
131 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
132 }
133#endif
134
135 flops1 = 1000000;
136 rc = pthread_create( &e_th, &attr, Thread, ( void * ) &flops1 );
137 if ( rc ) {
139 test_fail( __FILE__, __LINE__, "pthread_create", retval );
140 }
141
142 flops2 = 2000000;
143 rc = pthread_create( &f_th, &attr, Thread, ( void * ) &flops2 );
144 if ( rc ) {
146 test_fail( __FILE__, __LINE__, "pthread_create", retval );
147 }
148
149 flops3 = 4000000;
150 rc = pthread_create( &g_th, &attr, Thread, ( void * ) &flops3 );
151 if ( rc ) {
153 test_fail( __FILE__, __LINE__, "pthread_create", retval );
154 }
155
156 flops4 = 8000000;
157 rc = pthread_create( &h_th, &attr, Thread, ( void * ) &flops4 );
158 if ( rc ) {
160 test_fail( __FILE__, __LINE__, "pthread_create", retval );
161 }
162
163 pthread_attr_destroy( &attr );
164
165 flops5 = 500000;
166 Thread( &flops5 );
167
168 pthread_join( h_th, NULL );
169 pthread_join( g_th, NULL );
170 pthread_join( f_th, NULL );
171 pthread_join( e_th, NULL );
172
173 test_pass( __FILE__ );
174
175 pthread_exit( NULL );
176
177 return 1;
178}
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
#define PAPI_ECMP
Definition: f90papi.h:214
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
rc
Definition: pscanf.h:23
int quiet
Definition: rapl_overflow.c:19
void * Thread(void *arg)
Definition: thrspecific.c:21
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ Thread()

void * Thread ( void *  arg)

Definition at line 21 of file thrspecific.c.

22{
23 int retval;
24 void *arg2;
25 int i;
26
28 if ( retval != PAPI_OK ) {
29 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
30 }
31
32 if (!TESTS_QUIET) {
33 printf( "Thread %#x started, specific data is at %p\n",
34 ( int ) pthread_self( ), arg );
35 }
36
38 if ( retval != PAPI_OK ) {
39 test_fail( __FILE__, __LINE__, "PAPI_set_thr_specific", retval );
40 }
41
43 if ( retval != PAPI_OK ) {
44 test_fail( __FILE__, __LINE__, "PAPI_get_thr_specific", retval );
45 }
46
47 if ( arg != arg2 ) {
48 test_fail( __FILE__, __LINE__, "set vs get specific", 0 );
49 }
50
51 while ( processing ) {
52 if ( *( ( int * ) arg ) == 500000 ) {
53 sleep( 1 );
54
56 data.num = 10;
57 data.id = ( unsigned long * ) malloc( ( size_t ) data.num *
58 sizeof ( unsigned long ) );
59 data.data = ( void ** ) malloc( ( size_t ) data.num * sizeof ( void * ) );
60
62 ( void ** ) &data );
63 if ( retval != PAPI_OK ) {
64 test_fail( __FILE__, __LINE__, "PAPI_get_thr_specific",
65 retval );
66 }
67
68 if ( data.num != 5 ) {
69 test_fail( __FILE__, __LINE__, "data.num != 5", 0 );
70 }
71
72 if (!TESTS_QUIET) for ( i = 0; i < data.num; i++ ) {
73 printf( "Entry %d, Thread %#lx, Data Pointer %p, Value %d\n",
74 i, data.id[i], data.data[i], *( int * ) data.data[i] );
75 }
76 free(data.id);
77 free(data.data);
78 processing = 0;
79 }
80 }
81
83 if ( retval != PAPI_OK ) {
84 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
85 }
86
87 return NULL;
88}
int i
Retrieve a pointer to a thread specific data structure.
Notify PAPI that a thread has 'appeared'.
Store a pointer to a thread specific data structure.
Notify PAPI that a thread has 'disappeared'.
#define PAPI_USR1_TLS
Definition: f90papi.h:50
#define PAPI_TLS_ALL_THREADS
Definition: f90papi.h:173
int TESTS_QUIET
Definition: test_utils.c:18
long long int long long
Definition: sde_internal.h:85
PAPI_thread_id_t * id
Definition: papi.h:569
void ** data
Definition: papi.h:570
static volatile int processing
Definition: thrspecific.c:18
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ processing

volatile int processing = 1
static

Definition at line 18 of file thrspecific.c.