PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "papi_test.h"
41 
42 #ifdef _OPENMP
43 #include <omp.h>
44 #else
45 #error "This compiler does not understand OPENMP"
46 #endif
47 
48 const PAPI_hw_info_t *hw_info = NULL;
49 
50 void
51 Thread( int n )
52 {
53  int retval, num_tests = 1;
54  int EventSet1 = PAPI_NULL;
55  int PAPI_event, mask1;
56  int num_events1;
57  long long **values;
58  long long elapsed_us, elapsed_cyc;
60 
61  printf( "Thread %#x started\n", omp_get_thread_num( ) );
62  num_events1 = 2;
63 
64  /* add PAPI_TOT_CYC and one of the events in
65  PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
66  depending on the availability of the event
67  on the platform */
68  EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
69 
70  retval = PAPI_event_code_to_name( PAPI_event, event_name );
71  if ( retval != PAPI_OK )
72  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
73 
74  values = allocate_test_space( num_tests, num_events1 );
75 
76  elapsed_us = PAPI_get_real_usec( );
77 
78  elapsed_cyc = PAPI_get_real_cyc( );
79 
80  retval = PAPI_start( EventSet1 );
81  if ( retval != PAPI_OK )
82  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
83 
84  do_flops( n );
85 
86  retval = PAPI_stop( EventSet1, values[0] );
87  if ( retval != PAPI_OK )
88  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
89 
90  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
91 
92  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
93 
94  remove_test_events( &EventSet1, mask1 );
95 
96  if ( !TESTS_QUIET ) {
97  printf( "Thread %#x %-12s : \t%lld\n", omp_get_thread_num( ),
98  event_name, values[0][1] );
99  printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", omp_get_thread_num( ),
100  values[0][0] );
101  printf( "Thread %#x Real usec : \t%lld\n", omp_get_thread_num( ),
102  elapsed_us );
103  printf( "Thread %#x Real cycles : \t%lld\n", omp_get_thread_num( ),
104  elapsed_cyc );
105  }
106 
107  /* It is illegal for the threads to exit in OpenMP */
108  /* test_pass(__FILE__,0,0); */
109  free_test_space( values, num_tests );
110 
112  printf( "Thread %#x finished\n", omp_get_thread_num( ) );
113 }
114 
115 int
116 main( int argc, char **argv )
117 {
118  int maxthr, retval;
119  long long elapsed_us, elapsed_cyc;
120 
121  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
122 
124  if ( retval != PAPI_VER_CURRENT )
125  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
126 
127  hw_info = PAPI_get_hardware_info( );
128  if ( hw_info == NULL )
129  test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
130 
131  elapsed_us = PAPI_get_real_usec( );
132 
133  elapsed_cyc = PAPI_get_real_cyc( );
134 
135 
136  retval =
137  PAPI_thread_init( ( unsigned
138  long ( * )( void ) ) ( omp_get_thread_num ) );
139  if ( retval != PAPI_OK ) {
140  if ( retval == PAPI_ECMP )
141  test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
142  else
143  test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
144  }
145 #pragma omp parallel private(maxthr)
146  {
147  maxthr = omp_get_num_threads( );
148  Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
149  }
150  omp_set_num_threads( 1 );
151  Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
152  omp_set_num_threads( omp_get_max_threads( ) );
153 #pragma omp parallel private(maxthr)
154  {
155  maxthr = omp_get_num_threads( );
156  Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
157  }
158 
159  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
160 
161  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
162 
163  if ( !TESTS_QUIET ) {
164  printf( "Master real usec : \t%lld\n", elapsed_us );
165  printf( "Master real cycles : \t%lld\n", elapsed_cyc );
166  }
167 
168  test_pass( __FILE__, NULL, 0 );
169  exit( 0 );
170 }
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
Hardware info structure.
Definition: papi.h:775
#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
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
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
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6059
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
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
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