PAPI 7.1.0.0
Loading...
Searching...
No Matches
data_range.c
Go to the documentation of this file.
1/*
2* File: data_range.c
3* Author: Dan Terpstra
4* terpstra@cs.utk.edu
5* Mods: <your name here>
6* <your email address>
7*/
8
9/* This file performs the following test: */
10/* exercise the Itanium data address range interface */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15
16#include "papi.h"
17#include "papi_test.h"
18
19#define NUM 16384
20
21static void init_array( void );
22static int do_malloc_work( long loop );
23static int do_static_work( long loop );
24static void measure_load_store( vptr_t start, vptr_t end );
25static void measure_event( int index, PAPI_option_t * option );
26
32
33int
34main( int argc, char **argv )
35{
36 int retval;
37 const PAPI_exe_info_t *prginfo = NULL;
39
40 /* Set TESTS_QUIET variable */
41 tests_quiet( argc, argv );
42
43#if !defined(ITANIUM2) && !defined(ITANIUM3)
44 test_skip( __FILE__, __LINE__, "Currently only works on itanium2", 0 );
45 exit( 1 );
46#endif
47
48 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
49
50 init_array( );
51 printf( "Malloc'd array pointers: %p %p %p\n", &parray1, &parray2,
52 &parray3 );
53 printf( "Malloc'd array addresses: %p %p %p\n", parray1, parray2,
54 parray3 );
55 printf( "Static array addresses: %p %p %p\n", &array1, &array2,
56 &array3 );
57
58 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
59
60 if ( ( retval =
62 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
63
65 if ( hw_info == NULL )
66 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 );
67
68 prginfo = PAPI_get_executable_info( );
69 if ( prginfo == NULL )
70 test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", 1 );
71
72#if defined(linux) && defined(__ia64__)
73 sprintf( event_name[0], "loads_retired" );
74 sprintf( event_name[1], "stores_retired" );
77#else
78 test_skip( __FILE__, __LINE__, "only works for Itanium", PAPI_ENOSUPP );
79#endif
80
82 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
83
85 if ( retval != PAPI_OK )
86 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
87
89 if ( retval != PAPI_OK )
90 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
91 retval );
92
93/***************************************************************************************/
94 printf
95 ( "\n\nMeasure loads and stores on the pointers to the allocated arrays\n" );
96 printf( "Expected loads: %d; Expected stores: 0\n", NUM * 2 );
97 printf
98 ( "These loads result from accessing the pointers to compute array addresses.\n" );
99 printf
100 ( "They will likely disappear with higher levels of optimization.\n" );
101
102 measure_load_store( ( vptr_t ) & parray1, ( vptr_t ) ( &parray1 + 1 ) );
103 measure_load_store( ( vptr_t ) & parray2, ( vptr_t ) ( &parray2 + 1 ) );
104 measure_load_store( ( vptr_t ) & parray3, ( vptr_t ) ( &parray3 + 1 ) );
105/***************************************************************************************/
106 printf
107 ( "\n\nMeasure loads and stores on the allocated arrays themselves\n" );
108 printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );
109
113/***************************************************************************************/
114 printf( "\n\nMeasure loads and stores on the static arrays\n" );
115 printf
116 ( "These values will differ from the expected values by the size of the offsets.\n" );
117 printf( "Expected loads: %d; Expected stores: %d\n", NUM, NUM );
118
122/***************************************************************************************/
123
125 if ( retval != PAPI_OK )
126 test_fail( __FILE__, __LINE__, "PAPI_destroy", retval );
127
128 free( parray1 );
129 free( parray2 );
130 free( parray3 );
131
132 test_pass( __FILE__ );
133
134 return 0;
135
136}
137
138static void
140{
141 PAPI_option_t option;
142 int retval;
143
144 /* set up the optional address structure for starting and ending data addresses */
145 option.addr.eventset = EventSet;
146 option.addr.start = start;
147 option.addr.end = end;
148
149 if ( ( retval = PAPI_set_opt( PAPI_DATA_ADDRESS, &option ) ) != PAPI_OK )
150 test_fail( __FILE__, __LINE__, "PAPI_set_opt(PAPI_DATA_ADDRESS)",
151 retval );
152
153 measure_event( 0, &option );
154 measure_event( 1, &option );
155}
156
157static void
158measure_event( int index, PAPI_option_t * option )
159{
160 int retval;
161 long long value;
162
163 if ( ( retval = PAPI_add_event( EventSet, PAPI_event[index] ) ) != PAPI_OK )
164 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
165
166 if ( index == 0 ) {
167/* if ((retval = PAPI_get_opt(PAPI_DATA_ADDRESS, option)) != PAPI_OK)
168 test_fail(__FILE__, __LINE__, "PAPI_get_opt(PAPI_DATA_ADDRESS)", retval);
169*/
170 printf
171 ( "Requested Start Address: %p; Start Offset: %#5x; Actual Start Address: %p\n",
172 option->addr.start, option->addr.start_off,
173 option->addr.start - option->addr.start_off );
174 printf
175 ( "Requested End Address: %p; End Offset: %#5x; Actual End Address: %p\n",
176 option->addr.end, option->addr.end_off,
177 option->addr.end + option->addr.end_off );
178 }
179
181 if ( retval != PAPI_OK ) {
182 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
183 }
186 retval = PAPI_stop( EventSet, &value );
187 if ( retval != PAPI_OK ) {
188 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
189 }
190
191 printf( "%s: %lld\n", event_name[index], value );
192
193 if ( ( retval =
195 test_fail( __FILE__, __LINE__, "PAPI_remove_event", retval );
196}
197
198static void
200{
201 parray1 = ( int * ) malloc( NUM * sizeof ( int ) );
202 if ( parray1 == NULL )
203 test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
204 memset( parray1, 0x0, NUM * sizeof ( int ) );
205
206 parray2 = ( int * ) malloc( NUM * sizeof ( int ) );
207 if ( parray2 == NULL )
208 test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
209 memset( parray2, 0x0, NUM * sizeof ( int ) );
210
211 parray3 = ( int * ) malloc( NUM * sizeof ( int ) );
212 if ( parray3 == NULL )
213 test_fail( __FILE__, __LINE__, "No memory available!\n", 0 );
214 memset( parray3, 0x0, NUM * sizeof ( int ) );
215
216}
217
218static int
220{
221 int i;
222 int sum = 0;
223
224 for ( i = 0; i < loop; i++ ) {
225 array1[i] = i;
226 sum += array1[i];
227 }
228
229 for ( i = 0; i < loop; i++ ) {
230 array2[i] = i;
231 sum += array2[i];
232 }
233
234 for ( i = 0; i < loop; i++ ) {
235 array3[i] = i;
236 sum += array3[i];
237 }
238
239 return sum;
240}
241
242static int
244{
245 int i;
246 int sum = 0;
247
248 for ( i = 0; i < loop; i++ ) {
249 parray1[i] = i;
250 sum += parray1[i];
251 }
252
253 for ( i = 0; i < loop; i++ ) {
254 parray2[i] = i;
255 sum += parray2[i];
256 }
257
258 for ( i = 0; i < loop; i++ ) {
259 parray3[i] = i;
260 sum += parray3[i];
261 }
262
263 return sum;
264}
int i
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
add PAPI preset or native hardware event to an event set
Assign a component index to an existing but empty EventSet.
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Convert a name to a numeric hardware event code.
Get the executable's address space info.
get information about the system hardware
initialize the PAPI library.
removes a hardware event from a PAPI event set.
Set PAPI library or event set options.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static void init_array(void)
Definition: data_range.c:199
int EventSet
Definition: data_range.c:31
int array1[NUM]
Definition: data_range.c:28
static int do_malloc_work(long loop)
Definition: data_range.c:243
int array2[NUM]
Definition: data_range.c:28
static int do_static_work(long loop)
Definition: data_range.c:219
int * parray3
Definition: data_range.c:27
static void measure_event(int index, PAPI_option_t *option)
Definition: data_range.c:158
int * parray2
Definition: data_range.c:27
static void measure_load_store(vptr_t start, vptr_t end)
Definition: data_range.c:139
#define NUM
Definition: data_range.c:19
int PAPI_event[2]
Definition: data_range.c:30
int array3[NUM]
Definition: data_range.c:28
int * parray1
Definition: data_range.c:27
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_ENOSUPP
Definition: f90papi.h:244
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_DATA_ADDRESS
Definition: f90papi.h:89
static struct timeval start
double loop(long n)
Definition: kufrin.c:26
Return codes and api definitions.
void * vptr_t
Definition: papi.h:576
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 main()
Definition: pernode.c:20
get the executable's info
Definition: papi.h:696
Hardware info structure.
Definition: papi.h:774
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
PAPI_addr_range_option_t addr
Definition: papi.h:859
int retval
Definition: zero_fork.c:53