PAPI 7.1.0.0
Loading...
Searching...
No Matches
zero_smp.c
Go to the documentation of this file.
1/* This file performs the following test: start, stop and timer
2functionality for 2 slave native SMP threads
3
4 - It attempts to use the following two counters. It may use less
5depending on hardware counter resource limitations. These are counted
6in the default counting domain and default granularity, depending on
7the platform. Usually this is the user domain (PAPI_DOM_USER) and
8thread context (PAPI_GRN_THR).
9
10 + PAPI_FP_INS
11 + PAPI_TOT_CYC
12
13Each of 2 slave pthreads:
14 - Get cyc.
15 - Get us.
16 - Start counters
17 - Do flops
18 - Stop and read counters
19 - Get us.
20 - Get cyc.
21
22Master pthread:
23 - Get us.
24 - Get cyc.
25 - Fork threads
26 - Wait for threads to exit
27 - Get us.
28 - Get cyc.
29*/
30
31
32#include <stdio.h>
33#include <stdlib.h>
34
35#include "papi.h"
36#include "papi_test.h"
37
38#include "do_loops.h"
39
40#if defined(sun) && defined(sparc)
41#include <thread.h>
42#elif defined(mips) && defined(sgi) && defined(unix)
43#include <mpc.h>
44#elif defined(_AIX) || defined(__linux__)
45#include <pthread.h>
46#endif
47
48
49void
50Thread( int t, int n )
51{
52 int retval, num_tests = 1;
53 int EventSet1 = PAPI_NULL;
54 int PAPI_event, mask1;
55 int num_events1;
56 long long **values;
57 long long elapsed_us, elapsed_cyc;
59
60 /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
61 PAPI_TOT_INS, depending on the availability of the event on the
62 platform */
64
66 if ( retval != PAPI_OK )
67 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
68
70
72 if ( retval != PAPI_OK )
73 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
74
76
78
79 do_flops( n );
80
82
84
86 if ( retval != PAPI_OK )
87 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
88
90
91 if ( !TESTS_QUIET ) {
92 printf( "Thread %#x %-12s : \t%lld\n", t, event_name,
93 values[0][1] );
94 printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", t,
95 values[0][0] );
96 }
97
99 if ( !TESTS_QUIET ) {
100 printf( "Thread %#x Real usec : \t%lld\n", t, elapsed_us );
101 printf( "Thread %#x Real cycles : \t%lld\n", t, elapsed_cyc );
102 }
104}
105
106int
107main( int argc, char **argv )
108{
109 int i, retval, quiet;
110 long long elapsed_us, elapsed_cyc;
111
112 /* Set TESTS_QUIET variable */
113 quiet=tests_quiet( argc, argv );
114
116 if ( retval != PAPI_VER_CURRENT ) {
117 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
118 }
119
121
123
124#if defined(_AIX) || defined(__linux__)
125 retval =
126 PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
127 if ( retval != PAPI_OK ) {
128 if ( retval == PAPI_ECMP )
129 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
130 else
131 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
132 }
133#if defined(_AIX)
134#pragma ibm parallel_loop
135#endif
136
137#elif defined(sgi) && defined(mips)
138 retval =
139 PAPI_thread_init( ( unsigned long ( * )( void ) ) ( mp_my_threadnum ) );
140 if ( retval != PAPI_OK ) {
141 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
142 }
143#pragma parallel
144#pragma local(i)
145#pragma pfor
146#elif defined(sun) && defined(sparc)
147 retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( thr_self ) );
148 if ( retval != PAPI_OK ) {
149 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
150 }
151#pragma MP taskloop private(i)
152#else
153 if (!quiet) {
154 printf("This test only runs on AIX/IRIX/SOLOARIS\n");
155 }
156 test_skip(__FILE__, __LINE__, "Architecture not included in this test file yet.", 0);
157#endif
158 for ( i = 1; i < 3; i++ ) {
159 Thread( i, 10000000 * i );
160 }
161
163
165
166 if ( !quiet ) {
167 printf( "Master real usec : \t%lld\n", elapsed_us );
168 printf( "Master real cycles : \t%lld\n", elapsed_cyc );
169 }
170
171 // FIXME: we don't really validate anything here
172
173 test_pass( __FILE__ );
174
175 return 0;
176}
int i
Convert a numeric hardware event code to a name.
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.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Initialize thread support in the PAPI library.
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_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ECMP
Definition: f90papi.h:214
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
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:640
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int EventSet1
Definition: zero_fork.c:47
int num_events1
Definition: zero_fork.c:49
int mask1
Definition: zero_fork.c:48
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int num_tests
Definition: zero_fork.c:53
int retval
Definition: zero_fork.c:53
void Thread(int t, int n)
Definition: zero_smp.c:50