PAPI 7.1.0.0
Loading...
Searching...
No Matches
mendes-alt.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4
5#include "papi.h"
6#include "papi_test.h"
7
8#ifdef SETMAX
9#define MAX SETMAX
10#else
11#define MAX 10000
12#endif
13#define TIMES 1000
14
15#define PAPI_MAX_EVENTS 2
19static int EventSet = PAPI_NULL;
20
21void funcX( double a[MAX], double b[MAX], int n)
22{
23 int i, k;
24 for ( k = 0; k < TIMES; k++ )
25 for ( i = 0; i < n; i++ )
26 a[i] = a[i] * b[i] + 1.;
27}
28
29void funcA( double a[MAX], double b[MAX], int n)
30{
31 int i, k;
32 double t[MAX];
33 for ( k = 0; k < TIMES; k++ )
34 for ( i = 0; i < n; i++ ) {
35 t[i] = b[n - i];
36 b[i] = a[n - i];
37 a[i] = t[i];
38 }
39}
40
41int
42main( int argc, char **argv )
43{
44 int i, retval;
45 double a[MAX], b[MAX];
46 int quiet;
47
48 /* Set TESTS_QUIET variable */
49 quiet=tests_quiet( argc, argv );
50
51 for ( i = 0; i < MAX; i++ ) {
52 a[i] = 0.0;
53 b[i] = 0.;
54 }
55
56 for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
58
60 if ( retval != PAPI_VER_CURRENT )
61 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
62
63#ifdef MULTIPLEX
64 if ( !quiet ) {
65 printf( "Activating PAPI Multiplex\n" );
66 }
67
69 if ( retval != PAPI_OK ) {
70 test_fail( __FILE__, __LINE__, "PAPI multiplex init fail\n",
71 retval );
72 }
73
74#endif
75
77 if ( retval != PAPI_OK )
78 test_fail( __FILE__, __LINE__, "PAPI set event fail\n", retval );
79
80#ifdef MULTIPLEX
81 /* In Component PAPI, EventSets must be assigned a component index
82 before you can fiddle with their internals.
83 0 is always the cpu component */
85 if ( retval != PAPI_OK )
86 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
87 retval );
88
90 if (retval == PAPI_ENOSUPP) {
91 test_skip( __FILE__, __LINE__, "Multiplex not supported", 1 );
92 }
93 else if ( retval != PAPI_OK )
94 test_fail( __FILE__, __LINE__, "PAPI_set_multiplex fails \n", retval );
95#endif
96
98 if ( retval < PAPI_OK ) {
100 if ( retval < PAPI_OK ) {
101 if (!quiet) printf("Trouble adding events\n");
102 test_skip( __FILE__, __LINE__,
103 "PAPI add PAPI_FP_INS or PAPI_TOT_INS fail\n", retval );
104 } else if ( !quiet ) {
105 printf( "PAPI_TOT_INS\n" );
106 }
107 } else if ( !quiet ) {
108 printf( "PAPI_FP_INS\n" );
109 }
110
112 if ( retval < PAPI_OK )
113 test_fail( __FILE__, __LINE__, "PAPI add PAPI_TOT_CYC fail\n",
114 retval );
115 if ( !quiet ) {
116 printf( "PAPI_TOT_CYC\n" );
117 }
118
120 if ( retval != PAPI_OK )
121 test_fail( __FILE__, __LINE__, "PAPI start fail\n", retval );
122
123 funcX( a, b, MAX );
124
126 if ( retval != PAPI_OK )
127 test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
128
129 funcX( a, b, MAX );
130
132 if ( retval != PAPI_OK )
133 test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
134
135#ifdef RESET
137 if ( retval != PAPI_OK )
138 test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
139#endif
140
141 funcA( a, b, MAX );
142
144 if ( retval != PAPI_OK )
145 test_fail( __FILE__, __LINE__, "PAPI read fail \n", retval );
146
147 if ( !quiet ) {
148 printf( "values1 is:\n" );
149 for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
150 printf( LLDFMT15, PAPI_values1[i] );
151
152 printf( "\nvalues2 is:\n" );
153 for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
154 printf( LLDFMT15, PAPI_values2[i] );
155 printf( "\nvalues3 is:\n" );
156 for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
157 printf( LLDFMT15, PAPI_values3[i] );
158
159#ifndef RESET
160 printf( "\nPAPI value (2-1) is : \n" );
161 for ( i = 0; i < PAPI_MAX_EVENTS; i++ )
162 printf( LLDFMT15, PAPI_values2[i] - PAPI_values1[i] );
163 printf( "\nPAPI value (3-2) is : \n" );
164 for ( i = 0; i < PAPI_MAX_EVENTS; i++ ) {
165 long long diff;
166 diff = PAPI_values3[i] - PAPI_values2[i];
167 printf( LLDFMT15, diff);
168 if (diff<0) {
169 test_fail( __FILE__, __LINE__, "Multiplexed counter decreased", 1 );
170 }
171 }
172#endif
173
174 printf( "\n\nVerification:\n" );
175 printf( "From start to first PAPI_read %d fp operations are made.\n",
176 2 * MAX * TIMES );
177 printf( "Between 1st and 2nd PAPI_read %d fp operations are made.\n",
178 2 * MAX * TIMES );
179 printf( "Between 2nd and 3rd PAPI_read %d fp operations are made.\n",
180 0 );
181 printf( "\n" );
182 }
183
184 test_pass( __FILE__ );
185
186 return 0;
187
188}
int i
add PAPI preset or native hardware event to an event set
Assign a component index to an existing but empty EventSet.
Create a new empty PAPI EventSet.
initialize the PAPI library.
Initialize multiplex support in the PAPI library.
Read hardware counters from an event set.
Reset the hardware event counts in an event set.
Convert a standard event set to a multiplexed 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_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ENOSUPP
Definition: f90papi.h:244
#define PAPI_FP_INS
Definition: f90papi.h:366
#define PAPI_TOT_INS
Definition: f90papi.h:317
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
long long PAPI_values2[PAPI_MAX_EVENTS]
Definition: mendes-alt.c:17
void funcX(double a[MAX], double b[MAX], int n)
Definition: mendes-alt.c:21
static int EventSet
Definition: mendes-alt.c:19
#define MAX
Definition: mendes-alt.c:11
long long PAPI_values3[PAPI_MAX_EVENTS]
Definition: mendes-alt.c:18
long long PAPI_values1[PAPI_MAX_EVENTS]
Definition: mendes-alt.c:16
#define PAPI_MAX_EVENTS
Definition: mendes-alt.c:15
void funcA(double a[MAX], double b[MAX], int n)
Definition: mendes-alt.c:29
#define TIMES
Definition: mendes-alt.c:13
Return codes and api definitions.
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
#define LLDFMT15
Definition: papi_test.h:107
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
int retval
Definition: zero_fork.c:53