PAPI 7.1.0.0
Loading...
Searching...
No Matches
val_omp.c File Reference
Include dependency graph for val_omp.c:

Go to the source code of this file.

Functions

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

Variables

const int MAX_FLOPS = NUM_FLOPS
 
int TESTS_QUIET
 
const PAPI_hw_info_thw_info = NULL
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 117 of file val_omp.c.

118{
119 int tid, retval;
120 int maxthr = omp_get_max_threads( );
121 int flopper = 0;
122 long long *flops = calloc( maxthr, sizeof ( long long ) );
123 long long *flopi = calloc( maxthr, sizeof ( long long ) );
124
125 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
126
127 if ( maxthr < 2 )
128 test_skip( __FILE__, __LINE__, "omp_get_num_threads < 2", PAPI_EINVAL );
129
130 if ( ( flops == NULL ) || ( flopi == NULL ) )
131 test_fail( __FILE__, __LINE__, "calloc", PAPI_ENOMEM );
132
134 if ( retval != PAPI_VER_CURRENT )
135 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
136
138 if ( hw_info == NULL )
139 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
140
141 retval =
142 PAPI_thread_init( ( unsigned
143 long ( * )( void ) ) ( omp_get_thread_num ) );
144 if ( retval != PAPI_OK )
145 if ( retval == PAPI_ECMP )
146 test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
147 else
148 test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
149
150 flopper = Thread( 65536 ) / 65536;
151 printf( "flopper=%d\n", flopper );
152
153 for ( int i = 0; i < 100000; i++ )
154#pragma omp parallel private(tid)
155 {
156 tid = omp_get_thread_num( );
157 flopi[tid] = rand( ) * 3;
158 flops[tid] = Thread( ( flopi[tid] / flopper ) % MAX_FLOPS );
159#pragma omp barrier
160#pragma omp master
161 if ( flops[tid] < flopi[tid] ) {
162 printf( "test iteration=%d\n", i );
163 for ( int j = 0; j < omp_get_num_threads( ); j++ ) {
164 printf( "Thread %#x Value %6lld %c %6lld", j, flops[j],
165 ( flops[j] < flopi[j] ) ? '<' : '=', flopi[j] );
166 for ( int k = 0; k < omp_get_num_threads( ); k++ )
167 if ( ( k != j ) && ( flops[k] == flops[j] ) )
168 printf( " == Thread %#x!", k );
169 printf( "\n" );
170 }
171 test_fail( __FILE__, __LINE__, "value returned for thread",
172 PAPI_EBUG );
173 }
174 }
175
176 test_pass( __FILE__, NULL, 0 );
177 exit( 0 );
178}
int i
get information about the system hardware
initialize the PAPI library.
Initialize thread support in the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_EBUG
Definition: f90papi.h:176
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_EINVAL
Definition: f90papi.h:115
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_ENOMEM
Definition: f90papi.h:16
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
const PAPI_hw_info_t * hw_info
Definition: val_omp.c:42
const int MAX_FLOPS
Definition: val_omp.c:39
long long Thread(int n)
Definition: val_omp.c:45
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ Thread()

long long Thread ( int  n)

Definition at line 45 of file val_omp.c.

46{
47 int retval, num_tests = 1;
48 int EventSet1 = PAPI_NULL;
49 int PAPI_event, mask1;
50 int num_events1;
51 long long flops;
52 long long **values;
53 long long elapsed_us, elapsed_cyc;
55
56 /* printf("Thread(n=%d) %#x started\n", n, omp_get_thread_num()); */
57 num_events1 = 2;
58
59 /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
60 PAPI_TOT_INS, depending on the availability of the event on the
61 platform */
63
65 if ( retval != PAPI_OK )
66 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
67
69
70 do_flops( MAX_FLOPS - n ); /* prework for balance */
71
73
75
77 if ( retval != PAPI_OK )
78 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
79
80 do_flops( n );
81
83 if ( retval != PAPI_OK )
84 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
85
86 flops = ( values[0] )[0];
87
89
91
93
94 if ( !TESTS_QUIET ) {
95 /*printf("Thread %#x %-12s : \t%lld\t%d\n", omp_get_thread_num(), event_name,
96 (values[0])[0], n); */
97#if 0
98 printf( "Thread %#x PAPI_TOT_CYC: \t%lld\n", omp_get_thread_num( ),
99 values[0][0] );
100 printf( "Thread %#x Real usec : \t%lld\n", omp_get_thread_num( ),
101 elapsed_us );
102 printf( "Thread %#x Real cycles : \t%lld\n", omp_get_thread_num( ),
103 elapsed_cyc );
104#endif
105 }
106
107 /* It is illegal for the threads to exit in OpenMP */
108 /* test_pass(__FILE__,0,0); */
110
112 /* printf("Thread %#x finished\n", omp_get_thread_num()); */
113 return flops;
114}
Convert a numeric hardware event code to a name.
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
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
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_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void do_flops(int n)
Definition: multiplex.c:23
void free_test_space(long long **values, int num_tests)
Definition: test_utils.c:70
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:640
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int TESTS_QUIET
Definition: test_utils.c:18
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
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hw_info

const PAPI_hw_info_t* hw_info = NULL

Definition at line 42 of file val_omp.c.

◆ MAX_FLOPS

const int MAX_FLOPS = NUM_FLOPS

Definition at line 39 of file val_omp.c.

◆ TESTS_QUIET

int TESTS_QUIET
extern

Definition at line 18 of file test_utils.c.