PAPI 7.1.0.0
Loading...
Searching...
No Matches
zero_flip.c
Go to the documentation of this file.
1/* This file performs the following test: start, stop and timer functionality
2
3 - It attempts to use the following two counters.
4 It may use less depending on hardware counter resource limitations.
5 These are counted in the default counting domain and default granularity,
6 depending on the platform.
7 Usually this is the user domain (PAPI_DOM_USER) and
8 thread context (PAPI_GRN_THR).
9 + PAPI_FP_INS
10 + PAPI_TOT_CYC
11 - Get us.
12 - Start counters
13 - Do flops
14 - Stop and read counters
15 - Get us.
16*/
17
18#include <stdio.h>
19#include <stdlib.h>
20
21#include "papi.h"
22#include "papi_test.h"
23
24#include "do_loops.h"
25
26int
27main( int argc, char **argv )
28{
29 int retval, eventcnt, events[2], i, tmp;
31 int PAPI_event;
32 long long values1[2], values2[2];
33 long long elapsed_us, elapsed_cyc;
34 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_2MAX_STR_LEN];
35 int quiet;
36
37 /* Set TESTS_QUIET variable */
38 quiet = tests_quiet( argc, argv );
39
41 if ( retval != PAPI_VER_CURRENT )
42 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43
44 /* query and set up the right instruction to monitor */
47 else
49
51 if ( retval != PAPI_OK )
52 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
53 sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
54
56 if ( retval != PAPI_OK )
57 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
58
59 /* Add the events */
60 if (!quiet) printf( "Adding: %s\n", event_name );
62 if ( retval != PAPI_OK ) {
63 if (!quiet) printf("Trouble adding event\n");
64 test_skip( __FILE__, __LINE__, "PAPI_add_event", retval );
65 }
66
68 if ( retval != PAPI_OK )
69 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
70
71 /* Add them reversed to EventSet2 */
72
74 if ( retval != PAPI_OK )
75 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
76
77 eventcnt = 2;
78 retval = PAPI_list_events( EventSet1, events, &eventcnt );
79 if ( retval != PAPI_OK )
80 test_fail( __FILE__, __LINE__, "PAPI_list_events", retval );
81
82 for ( i = eventcnt - 1; i >= 0; i-- ) {
84 if ( retval != PAPI_OK )
85 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
86
88 if ( retval != PAPI_OK )
89 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
90 }
91
93
95
97 if ( retval != PAPI_OK )
98 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
99
101
102 retval = PAPI_stop( EventSet1, values1 );
103 if ( retval != PAPI_OK )
104 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
105
107 if ( retval != PAPI_OK )
108 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
109
111
112 retval = PAPI_stop( EventSet2, values2 );
113 if ( retval != PAPI_OK )
114 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
115
117
119
121 if ( retval != PAPI_OK )
122 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
123
125 if ( retval != PAPI_OK )
126 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
127
129 if ( retval != PAPI_OK )
130 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
131
133 if ( retval != PAPI_OK )
134 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
135
136 if ( !quiet ) {
137 printf( "Test case 0: start, stop.\n" );
138 printf( "-----------------------------------------------\n" );
139 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
140 printf( "Default domain is: %d (%s)\n", tmp,
142 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
143 printf( "Default granularity is: %d (%s)\n", tmp,
145 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
146 printf
147 ( "-------------------------------------------------------------------------\n" );
148
149 printf( "Test type : \t 1\t 2\n" );
150
151 sprintf( add_event_str, "%-12s : \t", event_name );
152 printf( TAB2, add_event_str, values1[0], values2[1] );
153 printf( TAB2, "PAPI_TOT_CYC : \t", values1[1], values2[0] );
154 printf( TAB1, "Real usec : \t", elapsed_us );
155 printf( TAB1, "Real cycles : \t", elapsed_cyc );
156
157 printf
158 ( "-------------------------------------------------------------------------\n" );
159
160 printf( "Verification: none\n" );
161 }
162
163 test_pass( __FILE__ );
164
165 return 0;
166
167}
double tmp
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a numeric hardware event code to a name.
Get PAPI library or event set options.
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.
list the events in an event set
Query if PAPI event exists.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
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_DEFGRN
Definition: f90papi.h:26
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_FP_OPS
Definition: f90papi.h:319
#define PAPI_2MAX_STR_LEN
Definition: f90papi.h:180
#define PAPI_TOT_INS
Definition: f90papi.h:317
#define PAPI_DEFDOM
Definition: f90papi.h:188
char events[MAX_EVENTS][BUFSIZ]
void do_flops(int n)
Definition: multiplex.c:23
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define TAB1
Definition: papi_test.h:98
#define TAB2
Definition: papi_test.h:99
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
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int EventSet2
Definition: rapl_overflow.c:17
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int EventSet1
Definition: zero_fork.c:47
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53