PAPI 7.1.0.0
Loading...
Searching...
No Matches
zero.c
Go to the documentation of this file.
1/* zero.c */
2
3/* This is possibly the most important PAPI tests, and is the one */
4/* that is often used as a quick test that PAPI is working. */
5/* We should make sure that it always passes, if possible. */
6
7/* Traditionally it used FLOPS, due to the importance of this to HPC. */
8/* This has been changed to use Instructions/Cycles as some recent */
9/* major Intel chips do not have good floating point events and would fail. */
10
11#include <stdio.h>
12#include <stdlib.h>
13
14#include "papi.h"
15#include "papi_test.h"
16
17#include "testcode.h"
18
19#define NUM_EVENTS 2
20
21#define NUM_LOOPS 200
22
23int main( int argc, char **argv ) {
24
25 int retval, tmp, result, i;
26 int EventSet1 = PAPI_NULL;
27 long long values[NUM_EVENTS];
28 long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
29 double ipc;
30 int quiet=0;
31
32 /* Set TESTS_QUIET variable */
33 quiet=tests_quiet( argc, argv );
34
35 /* Init the PAPI library */
37 if ( retval != PAPI_VER_CURRENT ) {
38 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
39 }
40
41 /* Initialize the EventSet */
43 if (retval!=PAPI_OK) {
44 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
45 }
46
47 /* Add PAPI_TOT_CYC */
49 if (retval!=PAPI_OK) {
50 if (!quiet) {
51 printf("Trouble adding PAPI_TOT_CYC: %s\n",
53 }
54 test_skip( __FILE__, __LINE__, "adding PAPI_TOT_CYC", retval );
55 }
56
57 /* Add PAPI_TOT_INS */
59 if (retval!=PAPI_OK) {
60 test_fail( __FILE__, __LINE__, "adding PAPI_TOT_INS", retval );
61 }
62
63 /* warm up the processor to pull it out of idle state */
64 for(i=0;i<100;i++) {
66 }
67
69 if (!quiet) printf("Instructions testcode not available\n");
70 test_skip( __FILE__, __LINE__, "No instructions code", retval );
71 }
72
73 /* Gather before stats */
76 elapsed_virt_us = PAPI_get_virt_usec( );
77 elapsed_virt_cyc = PAPI_get_virt_cyc( );
78
79 /* Start PAPI */
81 if ( retval != PAPI_OK ) {
82 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
83 }
84
85 /* our work code */
86 for(i=0;i<NUM_LOOPS;i++) {
88 }
89
90 /* Stop PAPI */
92 if ( retval != PAPI_OK ) {
93 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
94 }
95
96 /* Calculate total values */
97 elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
98 elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
101
102 /* Shutdown the EventSet */
103 retval = PAPI_remove_named_event( EventSet1, "PAPI_TOT_CYC" );
104 if (retval!=PAPI_OK) {
105 test_fail( __FILE__, __LINE__, "PAPI_remove_named_event", retval );
106 }
107
108 retval = PAPI_remove_named_event( EventSet1, "PAPI_TOT_INS" );
109 if (retval!=PAPI_OK) {
110 test_fail( __FILE__, __LINE__, "PAPI_remove_named_event", retval );
111 }
112
114 if (retval!=PAPI_OK) {
115 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
116 }
117
118 /* Calculate Instructions per Cycle, avoiding division by zero */
119 if (values[0]!=0) {
120 ipc = (double)values[1]/(double)values[0];
121 }
122 else {
123 ipc=0.0;
124 }
125
126 /* Print the results */
127 if ( !quiet ) {
128 printf( "Test case 0: start, stop.\n" );
129 printf( "-----------------------------------------------\n" );
130 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
131 printf( "Default domain is: %d (%s)\n", tmp,
133 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
134 printf( "Default granularity is: %d (%s)\n", tmp,
136 printf( "Using %d iterations 1 million instructions\n", NUM_LOOPS );
137 printf( "-------------------------------------------------------------------------\n" );
138
139 printf( "Test type : \t 1\n" );
140
141 /* cycles is first, other event second */
142 printf( "%-12s %12lld\n", "PAPI_TOT_CYC : \t", values[0] );
143 printf( "%-12s %12lld\n", "PAPI_TOT_INS : \t", values[1] );
144 printf( "%-12s %12.2lf\n", "IPC : \t", ipc );
145
146 printf( "%-12s %12lld\n", "Real usec : \t", elapsed_us );
147 printf( "%-12s %12lld\n", "Real cycles : \t", elapsed_cyc );
148 printf( "%-12s %12lld\n", "Virt usec : \t", elapsed_virt_us );
149 printf( "%-12s %12lld\n", "Virt cycles : \t", elapsed_virt_cyc );
150
151 printf( "-------------------------------------------------------------------------\n" );
152
153
154 printf( "Verification: PAPI_TOT_INS should be roughly %d\n", NUM_LOOPS*1000000 );
155
156 }
157
158 /* Check that TOT_INS is reasonable */
159 if (llabs(values[1] - (1000000*NUM_LOOPS)) > (1000000*NUM_LOOPS)) {
160 printf("%s Error of %.2f%%\n", "PAPI_TOT_INS", (100.0 * (double)(values[1] - (1000000*NUM_LOOPS)))/(1000000*NUM_LOOPS));
161 test_fail( __FILE__, __LINE__, "Instruction validation", 0 );
162 }
163
164 /* Check that TOT_CYC is non-zero */
165 if(values[0]==0) {
166 printf("Cycles is zero\n");
167 test_fail( __FILE__, __LINE__, "Cycles validation", 0 );
168 }
169
170 /* Unless you have an amazing processor, IPC should be < 100 */
171 if ((ipc <=0.01 ) || (ipc >=100.0)) {
172 printf("Unlikely IPC of %.2f%%\n", ipc);
173 test_fail( __FILE__, __LINE__, "IPC validation", 0 );
174 }
175
176 test_pass( __FILE__ );
177
178 return 0;
179}
volatile int result
double tmp
int i
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
Empty and destroy an 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.
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.
Returns a string describing the PAPI error code.
#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_DEFDOM
Definition: f90papi.h:188
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int instructions_million(void)
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
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
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
#define NUM_LOOPS
Definition: zero.c:21
#define NUM_EVENTS
Definition: zero.c:19
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