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

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 120 of file zero_pthreads.c.

121{
122 pthread_t e_th, f_th, g_th, h_th;
123 int flops1, flops2, flops3, flops4;
124 int retval, rc;
125 pthread_attr_t attr;
126 long long elapsed_us, elapsed_cyc;
127 int quiet;
128
129 /* Set TESTS_QUIET variable */
130 quiet = tests_quiet( argc, argv );
131
132 /* Init PAPI library */
134 if ( retval != PAPI_VER_CURRENT ) {
135 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
136 }
137
139 if (!quiet) printf("Can't find PAPI_TOT_INS\n");
140 test_skip(__FILE__,__LINE__,"Event missing",1);
141 }
142
144 if (!quiet) printf("Can't find PAPI_TOT_CYC\n");
145 test_skip(__FILE__,__LINE__,"Event missing",1);
146 }
147
148 retval = PAPI_thread_init( ( unsigned long ( * )( void ) )
149 ( pthread_self ) );
150
151 if ( retval != PAPI_OK ) {
152 if ( retval == PAPI_ECMP ) {
153 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
154 }
155 else {
156 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
157 }
158 }
159
161
163
164 pthread_attr_init( &attr );
165#ifdef PTHREAD_CREATE_UNDETACHED
166 pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED );
167#endif
168#ifdef PTHREAD_SCOPE_SYSTEM
169 retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
170 if ( retval != 0 )
171 test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval );
172#endif
173
174 flops1 = 1000000;
175 rc = pthread_create( &e_th, &attr, Thread, ( void * ) &flops1 );
176 if ( rc ) {
178 test_fail( __FILE__, __LINE__, "pthread_create", retval );
179 }
180 flops2 = 2000000;
181 rc = pthread_create( &f_th, &attr, Thread, ( void * ) &flops2 );
182 if ( rc ) {
184 test_fail( __FILE__, __LINE__, "pthread_create", retval );
185 }
186
187 flops3 = 4000000;
188 rc = pthread_create( &g_th, &attr, Thread, ( void * ) &flops3 );
189 if ( rc ) {
191 test_fail( __FILE__, __LINE__, "pthread_create", retval );
192 }
193
194 flops4 = 8000000;
195 rc = pthread_create( &h_th, &attr, Thread, ( void * ) &flops4 );
196 if ( rc ) {
198 test_fail( __FILE__, __LINE__, "pthread_create", retval );
199 }
200
201 pthread_attr_destroy( &attr );
202 flops1 = 500000;
203 Thread( &flops1 );
204 pthread_join( h_th, NULL );
205 pthread_join( g_th, NULL );
206 pthread_join( f_th, NULL );
207 pthread_join( e_th, NULL );
208
211
212 if ( !quiet ) {
213 printf( "Master real usec : \t%lld\n", elapsed_us );
214 printf( "Master real cycles : \t%lld\n", elapsed_cyc );
215 }
216
217 test_pass( __FILE__ );
218
219 pthread_exit( NULL );
220
221 return 0;
222}
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
initialize the PAPI library.
Query if PAPI event exists.
Initialize thread support in the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_TOT_INS
Definition: f90papi.h:317
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
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53
void * Thread(void *arg)
Definition: zero_pthreads.c:41
Here is the call graph for this function:

◆ Thread()

void * Thread ( void *  arg)

Definition at line 41 of file zero_pthreads.c.

42{
43 int retval, num_tests = 1;
44 int EventSet1 = PAPI_NULL;
45 int PAPI_event, mask1;
46 int num_events1;
47 long long **values;
48 long long elapsed_us, elapsed_cyc;
50
52 if ( retval != PAPI_OK ) {
53 test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
54 }
55
56 if (!TESTS_QUIET) {
57 printf( "Thread %#x started\n", ( int ) pthread_self( ) );
58 }
59
60 /* add PAPI_TOT_CYC and one of the events in
61 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
62 depending on the availability of the event
63 on the platform */
65 if (!TESTS_QUIET) {
66 printf("Events %d\n",num_events1);
67 }
68 if (num_events1<2) {
69 test_fail( __FILE__, __LINE__, "Not enough events", retval );
70 }
71
73 if ( retval != PAPI_OK ) {
74 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
75 }
76
78
81
83 if ( retval != PAPI_OK ) {
84 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
85 }
86
87 do_flops( *( int * ) arg );
88
90 if ( retval != PAPI_OK ) {
91 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
92 }
93
96
98
99 if ( !TESTS_QUIET ) {
100 printf( "Thread %#x %-12s : \t%lld\n", ( int ) pthread_self( ),
101 event_name, values[0][1] );
102 printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", (int) pthread_self(),
103 values[0][0] );
104 printf( "Thread %#x Real usec : \t%lld\n",
105 ( int ) pthread_self( ),
106 elapsed_us );
107 printf( "Thread %#x Real cycles : \t%lld\n", (int) pthread_self(),
108 elapsed_cyc );
109 }
110
112
114 if ( retval != PAPI_OK )
115 test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", retval );
116 return NULL;
117}
Convert a numeric hardware event code to a name.
Notify PAPI that a thread has 'appeared'.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Notify PAPI that a thread has 'disappeared'.
int PAPI_event[2]
Definition: data_range.c:30
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void do_flops(int n)
Definition: multiplex.c:23
int TESTS_QUIET
Definition: test_utils.c:18
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:640
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int EventSet1
Definition: zero_fork.c:47
int num_events1
Definition: zero_fork.c:49
int mask1
Definition: zero_fork.c:48
int num_tests
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function: