PAPI  5.7.0.0
zero_omp.c
Go to the documentation of this file.
1 /*
2 * File: zero_omp.c
3 * Author: Philip Mucci
4 * mucci@cs.utk.edu
5 * Mods: Nils Smeds
6 * smeds@pdc.kth.se
7 * Anders Nilsson
8 * anni@pdc.kth.se
9 */
10 
11 /* This file performs the following test: start, stop and timer
12 functionality for 2 slave OMP threads
13 
14  - It attempts to use the following two counters. It may use less
15 depending on hardware counter resource limitations. These are counted
16 in the default counting domain and default granularity, depending on
17 the platform. Usually this is the user domain (PAPI_DOM_USER) and
18 thread context (PAPI_GRN_THR).
19 
20  + PAPI_FP_INS
21  + PAPI_TOT_CYC
22 
23 Each thread inside the Thread routine:
24  - Get cyc.
25  - Get us.
26  - Start counters
27  - Do flops
28  - Stop and read counters
29  - Get us.
30  - Get cyc.
31 
32 Master serial thread:
33  - Get us.
34  - Get cyc.
35  - Run parallel for loop
36  - Get us.
37  - Get cyc.
38 */
39 
40 #include <stdio.h>
41 #include <stdlib.h>
42 
43 #include "papi.h"
44 #include "papi_test.h"
45 
46 #include "do_loops.h"
47 
48 #ifdef _OPENMP
49 #include <omp.h>
50 #else
51 #error "This compiler does not understand OPENMP"
52 #endif
53 
54 const PAPI_hw_info_t *hw_info = NULL;
55 
56 void
57 Thread( int n )
58 {
59  int retval, num_tests = 1;
60  int EventSet1 = PAPI_NULL;
61  int PAPI_event, mask1;
62  int num_events1;
63  long long **values;
64  long long elapsed_us, elapsed_cyc;
66 
67  if (!TESTS_QUIET) {
68  printf( "Thread %#x started\n", omp_get_thread_num( ) );
69  }
70 
71  /* add PAPI_TOT_CYC and one of the events in
72  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
73  depending on the availability of the event
74  on the platform */
76  if (num_events1==0) {
77  if (!TESTS_QUIET) printf("No events added!\n");
78  test_fail(__FILE__,__LINE__,"No events",0);
79  }
80 
82  if ( retval != PAPI_OK )
83  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
84 
86 
88 
90 
92  if ( retval != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
94 
95  do_flops( n );
96 
98  if ( retval != PAPI_OK )
99  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
100 
102 
104 
106 
107  if ( !TESTS_QUIET ) {
108  printf( "Thread %#x %-12s : \t%lld\n", omp_get_thread_num( ),
109  event_name, values[0][1] );
110  printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", omp_get_thread_num( ),
111  values[0][0] );
112  printf( "Thread %#x Real usec : \t%lld\n", omp_get_thread_num( ),
113  elapsed_us );
114  printf( "Thread %#x Real cycles : \t%lld\n", omp_get_thread_num( ),
115  elapsed_cyc );
116  }
117 
118  /* It is illegal for the threads to exit in OpenMP */
119  /* test_pass(__FILE__,0,0); */
121 
123  if (!TESTS_QUIET) {
124  printf( "Thread %#x finished\n", omp_get_thread_num( ) );
125  }
126 }
127 
128 int
129 main( int argc, char **argv )
130 {
131  int retval;
132  long long elapsed_us, elapsed_cyc;
133  int quiet;
134 
135  /* Set TESTS_QUIET variable */
136  quiet = tests_quiet( argc, argv );
137 
139  if ( retval != PAPI_VER_CURRENT ) {
140  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
141  }
142 
144  if ( hw_info == NULL ) {
145  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
146  }
147 
149  if (!quiet) printf("Can't find PAPI_TOT_INS\n");
150  test_skip(__FILE__,__LINE__,"Event missing",1);
151  }
152 
154  if (!quiet) printf("Can't find PAPI_TOT_CYC\n");
155  test_skip(__FILE__,__LINE__,"Event missing",1);
156  }
157 
159 
161 
162 
163  retval = PAPI_thread_init( ( unsigned long ( * )( void ) )
164  ( omp_get_thread_num ) );
165  if ( retval != PAPI_OK ) {
166  if ( retval == PAPI_ECMP ) {
167  if (!quiet) printf("Trouble init threads\n");
168  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
169  }
170  else {
171  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
172  }
173  }
174 #pragma omp parallel
175  {
176  Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
177  }
178  omp_set_num_threads( 1 );
179  Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
180  omp_set_num_threads( omp_get_max_threads( ) );
181 #pragma omp parallel
182  {
183  Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
184  }
185 
187 
189 
190  if ( !TESTS_QUIET ) {
191  printf( "Master real usec : \t%lld\n", elapsed_us );
192  printf( "Master real cycles : \t%lld\n", elapsed_cyc );
193  }
194 
195  test_pass( __FILE__ );
196 
197  return 0;
198 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
int PAPI_event[2]
Definition: data_range.c:30
void test_pass(const char *filename)
Definition: test_utils.c:432
Hardware info structure.
Definition: papi.h:781
int num_events1
Definition: zero_fork.c:49
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int retval
Definition: zero_fork.c:53
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int main(int argc, char **argv)
Definition: zero_omp.c:129
#define PAPI_ECMP
Definition: fpapi.h:109
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
int PAPI_library_init(int version)
Definition: papi.c:500
#define PAPI_TOT_INS
Definition: fpapi.h:186
int quiet
Definition: rapl_overflow.c:18
long long elapsed_cyc
Definition: zero_fork.c:50
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:617
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
#define PAPI_NULL
Definition: fpapi.h:13
const PAPI_hw_info_t * hw_info
Definition: zero_omp.c:54
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:684
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
int PAPI_unregister_thread(void)
Definition: papi.c:244
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void Thread(int n)
Definition: zero_omp.c:57
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
#define PAPI_TOT_CYC
Definition: fpapi.h:195
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
long long elapsed_us
Definition: zero_fork.c:50
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int EventSet1
Definition: zero_fork.c:47
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43