PAPI 7.1.0.0
Loading...
Searching...
No Matches
papi_sp_ops.c File Reference
Include dependency graph for papi_sp_ops.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 22 of file papi_sp_ops.c.

22 {
23
24 int num_runs=100,i;
25 long long high=0,low=0,average=0,expected=1500000;
26 double error,double_result;
27
28 long long count,total=0;
29 int quiet=0,retval,ins_result;
30 int eventset=PAPI_NULL;
31
32 quiet=tests_quiet(argc,argv);
33
34 if (!quiet) {
35 printf("\nTesting the PAPI_SP_OPS event.\n\n");
36 }
37
38 /* Init the PAPI library */
40 if ( retval != PAPI_VER_CURRENT ) {
41 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
42 }
43
44 /* Create the eventset */
46 if (retval!=PAPI_OK) {
47 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
48 }
49
50 /* Add FP_OPS event */
51 retval=PAPI_add_named_event(eventset,"PAPI_SP_OPS");
52 if (retval!=PAPI_OK) {
53 if (!quiet) fprintf(stderr,"PAPI_SP_OPS not available!\n");
54 test_skip( __FILE__, __LINE__, "adding PAPI_SP_OPS", retval );
55 }
56
57 /**************************************/
58 /* Test a loop with no floating point */
59 /**************************************/
60 total=0;
61 expected=0;
62
63 if (!quiet) {
64 printf("Testing a loop with %lld floating point (%d times):\n",
65 expected,num_runs);
66 }
67
68 for(i=0;i<num_runs;i++) {
69 PAPI_reset(eventset);
70 PAPI_start(eventset);
71
72 ins_result=branches_testcode();
73
74 retval=PAPI_stop(eventset,&count);
75
76 if (ins_result==CODE_UNIMPLEMENTED) {
77 fprintf(stderr,"\tCode unimplemented\n");
78 test_skip( __FILE__, __LINE__, "unimplemented", 0);
79 }
80
81 if (retval!=PAPI_OK) {
82 test_fail( __FILE__, __LINE__,
83 "reading PAPI_TOT_INS", retval );
84 }
85
86 if (count>high) high=count;
87 if ((low==0) || (count<low)) low=count;
88 total+=count;
89 }
90
91 average=(total/num_runs);
92
93 error=display_error(average,high,low,expected,quiet);
94
95 if (average>10) {
96 if (!quiet) printf("Unexpected FP event value\n");
97 test_fail( __FILE__, __LINE__, "Unexpected FP event", 1 );
98 }
99
100 if (!quiet) printf("\n");
101
102 /*******************************************/
103 /* Test a single-precision matrix multiply */
104 /*******************************************/
105 total=0; high=0; low=0;
107
108 num_runs=3;
109
110 if (!quiet) {
111 printf("Testing a matrix multiply with %lld single-precision FP operations (%d times)\n",
112 expected,num_runs);
113 }
114
115 for(i=0;i<num_runs;i++) {
116
117 PAPI_reset(eventset);
118 PAPI_start(eventset);
119
121
122 retval=PAPI_stop(eventset,&count);
123
124 if (retval!=PAPI_OK) {
125 test_fail( __FILE__, __LINE__,
126 "reading PAPI_TOT_INS", retval );
127 }
128
129 if (count>high) high=count;
130 if ((low==0) || (count<low)) low=count;
131 total+=count;
132 }
133
134 if (!quiet) printf("Result %lf\n",double_result);
135
136 average=(total/num_runs);
137
138 error=display_error(average,high,low,expected,quiet);
139
140 if ((error > 1.0) || (error<-1.0)) {
141 if (!quiet) printf("Instruction count off by more than 1%%\n");
142 test_fail( __FILE__, __LINE__, "Error too high", 1 );
143 }
144
145 if (!quiet) printf("\n");
146
147
148 /*******************************************/
149 /* Test a double-precision matrix multiply */
150 /*******************************************/
151 total=0; high=0; low=0;
153
155
156 num_runs=3;
157
158 if (!quiet) {
159 printf("Testing a matrix multiply with %lld double-precision FP operations (%d times)\n",
160 expected,num_runs);
161 }
162
163 for(i=0;i<num_runs;i++) {
164
165 PAPI_reset(eventset);
166 PAPI_start(eventset);
167
169
170 retval=PAPI_stop(eventset,&count);
171
172 if (retval!=PAPI_OK) {
173 test_fail( __FILE__, __LINE__,
174 "reading PAPI_TOT_INS", retval );
175 }
176
177 if (count>high) high=count;
178 if ((low==0) || (count<low)) low=count;
179 total+=count;
180 }
181
182 if (!quiet) printf("Result %lf\n",double_result);
183
184 average=(total/num_runs);
185
186 error=display_error(average,high,low,expected,quiet);
187
188 if ((error > 1.0) || (error<-1.0)) {
189 if (!quiet) printf("Instruction count off by more than 1%%\n");
190 test_fail( __FILE__, __LINE__, "Error too high", 1 );
191 }
192
193 if (!quiet) printf("\n");
194
195 test_pass( __FILE__ );
196
198
199 return 0;
200}
int i
int branches_testcode(void)
static long count
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
double display_error(long long average, long long high, long long low, long long expected, int quiet)
Definition: display_error.c:7
double flops_double_matrix_matrix_multiply(void)
int flops_double_init_matrix(void)
float flops_float_matrix_matrix_multiply(void)
int flops_float_init_matrix(void)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
FILE * stderr
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
int quiet
Definition: rapl_overflow.c:19
static int total
Definition: rapl_overflow.c:9
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: