PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zero_omp.c File Reference
Include dependency graph for zero_omp.c:

Go to the source code of this file.

Functions

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

Variables

const PAPI_hw_info_thw_info = NULL
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 129 of file zero_omp.c.

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 
158  elapsed_us = PAPI_get_real_usec( );
159 
160  elapsed_cyc = PAPI_get_real_cyc( );
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 
186  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
187 
188  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
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 }
void test_pass(const char *filename)
Definition: test_utils.c:432
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_thread_init(unsigned long int(*id_fn)(void))
Definition: papi.c:123
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
long long elapsed_cyc
Definition: zero_fork.c:50
#define PAPI_ECMP
Definition: papi.h:256
int PAPI_query_event(int EventCode)
Definition: papi.c:684
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
int TESTS_QUIET
Definition: test_utils.c:18
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
static void * Thread(void *arg)
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:50
#define PAPI_VER_CURRENT
Definition: papi.h:225
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28

Here is the call graph for this function:

void Thread ( int  n)

Definition at line 57 of file zero_omp.c.

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 */
75  EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
76  if (num_events1==0) {
77  if (!TESTS_QUIET) printf("No events added!\n");
78  test_fail(__FILE__,__LINE__,"No events",0);
79  }
80 
81  retval = PAPI_event_code_to_name( PAPI_event, event_name );
82  if ( retval != PAPI_OK )
83  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
84 
85  values = allocate_test_space( num_tests, num_events1 );
86 
87  elapsed_us = PAPI_get_real_usec( );
88 
89  elapsed_cyc = PAPI_get_real_cyc( );
90 
91  retval = PAPI_start( EventSet1 );
92  if ( retval != PAPI_OK )
93  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
94 
95  do_flops( n );
96 
97  retval = PAPI_stop( EventSet1, values[0] );
98  if ( retval != PAPI_OK )
99  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
100 
101  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
102 
103  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
104 
105  remove_test_events( &EventSet1, mask1 );
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); */
120  free_test_space( values, num_tests );
121 
123  if (!TESTS_QUIET) {
124  printf( "Thread %#x finished\n", omp_get_thread_num( ) );
125  }
126 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
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
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
return PAPI_OK
Definition: linux-nvml.c:497
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:615
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
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
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
int PAPI_unregister_thread(void)
Definition: papi.c:244
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
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: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

Here is the call graph for this function:

Variable Documentation

const PAPI_hw_info_t* hw_info = NULL

Definition at line 54 of file zero_omp.c.