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

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 14 of file zero_named.c.

15{
16 int retval, num_tests = 1, tmp;
17 int EventSet = PAPI_NULL;
18 int num_events = 2;
19 long long **values;
20 long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
21 const char *event_names[] = {"PAPI_TOT_CYC","PAPI_TOT_INS"};
22 char add_event_str[PAPI_MAX_STR_LEN];
23 double cycles_error;
24 int quiet;
25
26 /* Set TESTS_QUIET variable */
27 quiet=tests_quiet( argc, argv );
28
29 /* Init the PAPI library */
31 if ( retval != PAPI_VER_CURRENT ) {
32 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
33 }
34
35 /* Verify that the named events exist */
37 if ( retval == PAPI_OK) {
39 }
40 if ( retval != PAPI_OK ) {
41 if (!quiet) printf("Trouble querying events\n");
42 test_skip( __FILE__, __LINE__, "PAPI_query_named_event", retval );
43 }
44
45 /* Create an empty event set */
47 if ( retval != PAPI_OK )
48 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
49
50 /* add the events named above */
52 if ( retval != PAPI_OK ) {
53 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
54 test_fail( __FILE__, __LINE__, add_event_str, retval );
55 }
56
58 if ( retval != PAPI_OK ) {
59 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
60 test_fail( __FILE__, __LINE__, add_event_str, retval );
61 }
62
64
65 /* Gather before stats */
68 elapsed_virt_us = PAPI_get_virt_usec( );
69 elapsed_virt_cyc = PAPI_get_virt_cyc( );
70
71 /* Start PAPI */
73 if ( retval != PAPI_OK ) {
74 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
75 }
76
77 /* our test code */
79
80 /* Stop PAPI */
82 if ( retval != PAPI_OK ) {
83 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
84 }
85
86 /* Calculate total values */
87 elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
88 elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
91
92 /* remove PAPI_TOT_CYC and PAPI_TOT_INS */
94 if ( retval != PAPI_OK ) {
95 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[0] );
96 test_fail( __FILE__, __LINE__, add_event_str, retval );
97 }
98
100 if ( retval != PAPI_OK ) {
101 sprintf( add_event_str, "PAPI_add_named_event[%s]", event_names[1] );
102 test_fail( __FILE__, __LINE__, add_event_str, retval );
103 }
104
105 if ( !quiet ) {
106 printf( "PAPI_{query, add, remove}_named_event API test.\n" );
107 printf( "-----------------------------------------------\n" );
108 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
109 printf( "Default domain is: %d (%s)\n", tmp,
111 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
112 printf( "Default granularity is: %d (%s)\n", tmp,
114 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
115 printf( "-------------------------------------------------------------------------\n" );
116
117 printf( "Test type : \t 1\n" );
118
119 /* cycles is first, other event second */
120 sprintf( add_event_str, "%-12s : \t", event_names[0] );
121 printf( TAB1, add_event_str, values[0][0] );
122 sprintf( add_event_str, "%-12s : \t", event_names[1] );
123 printf( TAB1, add_event_str, values[0][1] );
124
125 printf( TAB1, "Real usec : \t", elapsed_us );
126 printf( TAB1, "Real cycles : \t", elapsed_cyc );
127 printf( TAB1, "Virt usec : \t", elapsed_virt_us );
128 printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
129
130 printf( "-------------------------------------------------------------------------\n" );
131
132 printf( "Verification: PAPI_TOT_CYC should be roughly real_cycles\n" );
133 cycles_error=100.0*((double)values[0][0] - (double)elapsed_cyc)/
134 (double)values[0][0];
135 if (cycles_error>10.0) {
136 printf("Error of %.2f%%\n",cycles_error);
137 test_fail( __FILE__, __LINE__, "validation", 0 );
138 }
139
140 }
141 test_pass( __FILE__ );
142
143 return 0;
144}
static const char * event_names[2]
Definition: Gamum.c:27
double tmp
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
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
get virtual time counter value in clock cycles
get virtual time counter values in microseconds
initialize the PAPI library.
Query if a named PAPI event exists.
removes a named hardware event from a PAPI event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#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_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_DEFDOM
Definition: f90papi.h:188
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
void do_flops(int n)
Definition: multiplex.c:23
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
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
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
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
Here is the call graph for this function: