PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zero_smp.c
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /* This file performs the following test: start, stop and timer
4 functionality for 2 slave native SMP threads
5 
6  - It attempts to use the following two counters. It may use less
7 depending on hardware counter resource limitations. These are counted
8 in the default counting domain and default granularity, depending on
9 the platform. Usually this is the user domain (PAPI_DOM_USER) and
10 thread context (PAPI_GRN_THR).
11 
12  + PAPI_FP_INS
13  + PAPI_TOT_CYC
14 
15 Each of 2 slave pthreads:
16  - Get cyc.
17  - Get us.
18  - Start counters
19  - Do flops
20  - Stop and read counters
21  - Get us.
22  - Get cyc.
23 
24 Master pthread:
25  - Get us.
26  - Get cyc.
27  - Fork threads
28  - Wait for threads to exit
29  - Get us.
30  - Get cyc.
31 */
32 
33 
34 #include "papi_test.h"
35 
36 #if defined(sun) && defined(sparc)
37 #include <thread.h>
38 #elif defined(mips) && defined(sgi) && defined(unix)
39 #include <mpc.h>
40 #elif defined(_AIX)
41 #include <pthread.h>
42 #endif
43 
44 
45 void
46 Thread( int t, int n )
47 {
48  int retval, num_tests = 1;
49  int EventSet1 = PAPI_NULL;
50  int PAPI_event, mask1;
51  int num_events1;
52  long long **values;
53  long long elapsed_us, elapsed_cyc;
55 
56  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
57  PAPI_TOT_INS, depending on the availability of the event on the
58  platform */
59  EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
60 
61  retval = PAPI_event_code_to_name( PAPI_event, event_name );
62  if ( retval != PAPI_OK )
63  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
64 
65  values = allocate_test_space( num_tests, num_events1 );
66 
67  retval = PAPI_start( EventSet1 );
68  if ( retval != PAPI_OK )
69  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
70 
71  elapsed_us = PAPI_get_real_usec( );
72 
73  elapsed_cyc = PAPI_get_real_cyc( );
74 
75  do_flops( n );
76 
77  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
78 
79  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
80 
81  retval = PAPI_stop( EventSet1, values[0] );
82  if ( retval != PAPI_OK )
83  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
84 
85  remove_test_events( &EventSet1, mask1 );
86 
87  if ( !TESTS_QUIET ) {
88  printf( "Thread %#x %-12s : \t%lld\n", t, event_name,
89  values[0][1] );
90  printf( "Thread %#x PAPI_TOT_CYC : \t%lld\n", t,
91  values[0][0] );
92  }
93 
94  free_test_space( values, num_tests );
95  if ( !TESTS_QUIET ) {
96  printf( "Thread %#x Real usec : \t%lld\n", t, elapsed_us );
97  printf( "Thread %#x Real cycles : \t%lld\n", t, elapsed_cyc );
98  }
100 }
101 
102 int
103 main( int argc, char **argv )
104 {
105  int i, retval;
106  long long elapsed_us, elapsed_cyc;
107 
108  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
109 
111  if ( retval != PAPI_VER_CURRENT )
112  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
113 
114  elapsed_us = PAPI_get_real_usec( );
115 
116  elapsed_cyc = PAPI_get_real_cyc( );
117 
118 #if defined(_AIX)
119  retval =
120  PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
121  if ( retval != PAPI_OK ) {
122  if ( retval == PAPI_ECMP )
123  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
124  else
125  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
126  }
127 #pragma ibm parallel_loop
128 #elif defined(sgi) && defined(mips)
129  retval =
130  PAPI_thread_init( ( unsigned long ( * )( void ) ) ( mp_my_threadnum ) );
131  if ( retval != PAPI_OK ) {
132  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
133  }
134 #pragma parallel
135 #pragma local(i)
136 #pragma pfor
137 #elif defined(sun) && defined(sparc)
138  retval = PAPI_thread_init( ( unsigned long ( * )( void ) ) ( thr_self ) );
139  if ( retval != PAPI_OK ) {
140  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
141  }
142 #pragma MP taskloop private(i)
143 #else
144  test_skip(__FILE__, __LINE__, "Architecture not included in this test file yet.", 0);
145 #endif
146  for ( i = 1; i < 3; i++ )
147  Thread( i, 10000000 * i );
148 
149  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
150 
151  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
152 
153  if ( !TESTS_QUIET ) {
154  printf( "Master real usec : \t%lld\n", elapsed_us );
155  printf( "Master real cycles : \t%lld\n", elapsed_cyc );
156  }
157  test_pass( __FILE__, NULL, 0 );
158  exit( 1 );
159 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
int mask1
Definition: zero_fork.c:41
int PAPI_event[2]
Definition: data_range.c:24
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
int num_events1
Definition: zero_fork.c:42
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
t
Definition: iozone.c:23562
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:118
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
long long elapsed_cyc
Definition: zero_fork.c:43
#define PAPI_ECMP
Definition: fpapi.h:109
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:680
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:131
void * Thread(void *arg)
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
long long PAPI_get_real_usec(void)
Definition: papi.c:6138
int PAPI_unregister_thread(void)
Definition: papi.c:239
long long PAPI_get_real_cyc(void)
Definition: papi.c:6091
int PAPI_start(int EventSet)
Definition: papi.c:2026
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
int EventSet1
Definition: zero_fork.c:40
int n
Definition: mendes-alt.c:164