PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mpifirst.c
Go to the documentation of this file.
1 /* This file performs the following test: start, read, stop and again functionality
2 
3  - It attempts to use the following three counters. It may use less depending on
4  hardware counter resource limitations. These are counted in the default counting
5  domain and default granularity, depending on the platform. Usually this is
6  the user domain (PAPI_DOM_USER) and thread context (PAPI_GRN_THR).
7  + PAPI_FP_INS or PAPI_TOT_INS if PAPI_FP_INS doesn't exist
8  + PAPI_TOT_CYC
9  - Start counters
10  - Do flops
11  - Read counters
12  - Reset counters
13  - Do flops
14  - Read counters
15  - Do flops
16  - Read counters
17  - Do flops
18  - Stop and read counters
19  - Read counters
20 */
21 
22 #include "papi_test.h"
23 
24 extern int TESTS_QUIET; /* Declared in test_utils.c */
25 
26 int
27 main( int argc, char **argv )
28 {
29  int retval, num_tests = 5, num_events, tmp;
30  long long **values;
31  int EventSet = PAPI_NULL;
32  int PAPI_event, mask;
33  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
34 
35 
36  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
37 
38  MPI_Init( argc, argv );
39 
41  if ( retval != PAPI_VER_CURRENT )
42  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
43 
44  /* query and set up the right instruction to monitor */
45  if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
46  PAPI_event = PAPI_FP_INS;
47  mask = MASK_FP_INS | MASK_TOT_CYC;
48  } else {
49  PAPI_event = PAPI_TOT_INS;
50  mask = MASK_TOT_INS | MASK_TOT_CYC;
51  }
52 
53  retval = PAPI_event_code_to_name( PAPI_event, event_name );
54  if ( retval != PAPI_OK )
55  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
56  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
57 
58  EventSet = add_test_events( &num_events, &mask );
59 
60  values = allocate_test_space( num_tests, num_events );
61 
62  retval = PAPI_start( EventSet );
63  if ( retval != PAPI_OK )
64  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
65 
67 
68  retval = PAPI_read( EventSet, values[0] );
69  if ( retval != PAPI_OK )
70  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
71 
72  retval = PAPI_reset( EventSet );
73  if ( retval != PAPI_OK )
74  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
75 
77 
78  retval = PAPI_read( EventSet, values[1] );
79  if ( retval != PAPI_OK )
80  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
81 
83 
84  retval = PAPI_read( EventSet, values[2] );
85  if ( retval != PAPI_OK )
86  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
87 
89 
90  retval = PAPI_stop( EventSet, values[3] );
91  if ( retval != PAPI_OK )
92  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
93 
94  retval = PAPI_read( EventSet, values[4] );
95  if ( retval != PAPI_OK )
96  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
97 
98  remove_test_events( &EventSet, mask );
99 
100  if ( !TESTS_QUIET ) {
101  printf( "Test case 1: Non-overlapping start, stop, read.\n" );
102  printf( "-----------------------------------------------\n" );
103  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
104  printf( "Default domain is: %d (%s)\n", tmp,
105  stringify_all_domains( tmp ) );
106  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
107  printf( "Default granularity is: %d (%s)\n", tmp,
108  stringify_granularity( tmp ) );
109  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
110  printf
111  ( "-------------------------------------------------------------------------\n" );
112 
113  printf( "Test type : \t1\t\t2\t\t3\t\t4\t\t5\n" );
114  sprintf( add_event_str, "%s : ", event_name );
115  printf( TAB5, add_event_str,
116  ( values[0] )[0], ( values[1] )[0], ( values[2] )[0],
117  ( values[3] )[0], ( values[4] )[0] );
118  printf( TAB5, "PAPI_TOT_CYC: ", ( values[0] )[1], ( values[1] )[1],
119  ( values[2] )[1], ( values[3] )[1], ( values[4] )[1] );
120  printf
121  ( "-------------------------------------------------------------------------\n" );
122 
123  printf( "Verification:\n" );
124  printf( "Column 1 approximately equals column 2\n" );
125  printf( "Column 3 approximately equals 2 * column 2\n" );
126  printf( "Column 4 approximately equals 3 * column 2\n" );
127  printf( "Column 4 exactly equals column 5\n" );
128  }
129 
130  {
131  long long min, max;
132  min = ( long long ) ( values[1][0] * .9 );
133  max = ( long long ) ( values[1][0] * 1.1 );
134 
135  if ( values[0][0] > max || values[0][0] < min ||
136  values[2][0] > ( 2 * max )
137  || values[2][0] < ( 2 * min ) || values[3][0] > ( 3 * max )
138  || values[3][0] < ( 3 * min )
139  || values[3][0] != values[4][0] ) {
140  printf( "min: " );
141  printf( LLDFMT, min );
142  printf( "max: " );
143  printf( LLDFMT, max );
144  printf( "1st: " );
145  printf( LLDFMT, values[0][0] );
146  printf( "2nd: " );
147  printf( LLDFMT, values[1][0] );
148  printf( "3rd: " );
149  printf( LLDFMT, values[2][0] );
150  printf( "4th: " );
151  printf( LLDFMT, values[3][0] );
152  printf( "5th: " );
153  printf( LLDFMT, values[4][0] );
154  printf( "\n" );
155  test_fail( __FILE__, __LINE__, event_name, 1 );
156  }
157 
158  min = ( long long ) ( values[1][1] * .9 );
159  max = ( long long ) ( values[1][1] * 1.1 );
160  if ( values[0][1] > max || values[0][1] < min ||
161  values[2][1] > ( 2 * max )
162  || values[2][1] < ( 2 * min ) || values[3][1] > ( 3 * max )
163  || values[3][1] < ( 3 * min )
164  || values[3][1] != values[4][1] ) {
165  test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC", 1 );
166  }
167  }
168  test_pass( __FILE__, values, num_tests );
169 
170  MPI_Finalize( );
171  exit( 1 );
172 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2258
#define NUM_FLOPS
int PAPI_event[2]
Definition: data_range.c:24
off64_t max
Definition: libasync.c:331
int PAPI_reset(int EventSet)
Definition: papi.c:2403
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
#define PAPI_NULL
Definition: papi.h:290
int EventSet
Definition: data_range.c:25
int num_events
#define PAPI_TOT_INS
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
#define MASK_FP_INS
Definition: papi_test.h:47
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:497
char * stringify_all_domains(int domains)
Definition: test_utils.c:369
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4082
#define TAB5
Definition: papi_test.h:116
#define PAPI_DEFGRN
Definition: papi.h:432
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
#define MASK_TOT_CYC
Definition: papi_test.h:49
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:926
int num_tests
Definition: zero_fork.c:46
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:698
#define LLDFMT
Definition: papi_test.h:118
#define MASK_TOT_INS
Definition: papi_test.h:48
#define PAPI_DEFDOM
Definition: papi.h:430
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2503
int PAPI_start(int EventSet)
Definition: papi.c:2053
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
#define PAPI_VER_CURRENT
Definition: papi.h:223
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:277
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:213
#define PAPI_FP_INS