PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
12functionality for 2 slave OMP threads
13
14 - It attempts to use the following two counters. It may use less
15depending on hardware counter resource limitations. These are counted
16in the default counting domain and default granularity, depending on
17the platform. Usually this is the user domain (PAPI_DOM_USER) and
18thread context (PAPI_GRN_THR).
19
20 + PAPI_FP_INS
21 + PAPI_TOT_CYC
22
23Each 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
32Master 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
54const PAPI_hw_info_t *hw_info = NULL;
55
56void
57Thread( 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
128unsigned long omp_get_thread_num_wrapper(void){
129 return (unsigned long)omp_get_thread_num();
130}
131
132int
133main( int argc, char **argv )
134{
135 int retval;
136 long long elapsed_us, elapsed_cyc;
137 int quiet;
138
139 /* Set TESTS_QUIET variable */
140 quiet = tests_quiet( argc, argv );
141
143 if ( retval != PAPI_VER_CURRENT ) {
144 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
145 }
146
148 if ( hw_info == NULL ) {
149 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
150 }
151
153 if (!quiet) printf("Can't find PAPI_TOT_INS\n");
154 test_skip(__FILE__,__LINE__,"Event missing",1);
155 }
156
158 if (!quiet) printf("Can't find PAPI_TOT_CYC\n");
159 test_skip(__FILE__,__LINE__,"Event missing",1);
160 }
161
163
165
166
168 if ( retval != PAPI_OK ) {
169 if ( retval == PAPI_ECMP ) {
170 if (!quiet) printf("Trouble init threads\n");
171 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
172 }
173 else {
174 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
175 }
176 }
177#pragma omp parallel
178 {
179 Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
180 }
181 omp_set_num_threads( 1 );
182 Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
183 omp_set_num_threads( omp_get_max_threads( ) );
184#pragma omp parallel
185 {
186 Thread( 1000000 * ( omp_get_thread_num( ) + 1 ) );
187 }
188
190
192
193 if ( !TESTS_QUIET ) {
194 printf( "Master real usec : \t%lld\n", elapsed_us );
195 printf( "Master real cycles : \t%lld\n", elapsed_cyc );
196 }
197
198 test_pass( __FILE__ );
199
200 return 0;
201}
Convert a numeric hardware event code to a name.
get information about the system hardware
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.
Query if PAPI event exists.
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_TOT_CYC
Definition: f90papi.h:308
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_TOT_INS
Definition: f90papi.h:317
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
Hardware info structure.
Definition: papi.h:774
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
const PAPI_hw_info_t * hw_info
Definition: zero_omp.c:54
void Thread(int n)
Definition: zero_omp.c:57
unsigned long omp_get_thread_num_wrapper(void)
Definition: zero_omp.c:128