PAPI  5.6.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 <stdio.h>
23 #include <string.h>
24 #include <mpi.h>
25 
26 #include "papi.h"
27 #include "papi_test.h"
28 
29 int
30 main( int argc, char **argv )
31 {
32  int retval, num_tests = 5, num_events, tmp;
33  long long **values;
34  int EventSet = PAPI_NULL;
35  int PAPI_event, mask;
36  char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
37  int quiet;
38 
39  /* Set TESTS_QUIET variable */
40  quiet=tests_quiet( argc, argv );
41 
42 
43  MPI_Init( argc, argv );
44 
46  if ( retval != PAPI_VER_CURRENT )
47  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
48 
49  /* query and set up the right instruction to monitor */
50  if ( PAPI_query_event( PAPI_FP_INS ) == PAPI_OK ) {
51  PAPI_event = PAPI_FP_INS;
52  mask = MASK_FP_INS | MASK_TOT_CYC;
53  } else {
54  PAPI_event = PAPI_TOT_INS;
55  mask = MASK_TOT_INS | MASK_TOT_CYC;
56  }
57 
58  retval = PAPI_event_code_to_name( PAPI_event, event_name );
59  if ( retval != PAPI_OK )
60  test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
61  sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
62 
63  EventSet = add_test_events( &num_events, &mask );
64 
65  values = allocate_test_space( num_tests, num_events );
66 
67  retval = PAPI_start( EventSet );
68  if ( retval != PAPI_OK )
69  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
70 
72 
73  retval = PAPI_read( EventSet, values[0] );
74  if ( retval != PAPI_OK )
75  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
76 
77  retval = PAPI_reset( EventSet );
78  if ( retval != PAPI_OK )
79  test_fail( __FILE__, __LINE__, "PAPI_reset", retval );
80 
82 
83  retval = PAPI_read( EventSet, values[1] );
84  if ( retval != PAPI_OK )
85  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
86 
88 
89  retval = PAPI_read( EventSet, values[2] );
90  if ( retval != PAPI_OK )
91  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
92 
94 
95  retval = PAPI_stop( EventSet, values[3] );
96  if ( retval != PAPI_OK )
97  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
98 
99  retval = PAPI_read( EventSet, values[4] );
100  if ( retval != PAPI_OK )
101  test_fail( __FILE__, __LINE__, "PAPI_read", retval );
102 
103  remove_test_events( &EventSet, mask );
104 
105  if ( !quiet ) {
106  printf( "Test case 1: Non-overlapping start, stop, read.\n" );
107  printf( "-----------------------------------------------\n" );
108  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
109  printf( "Default domain is: %d (%s)\n", tmp,
110  stringify_all_domains( tmp ) );
111  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
112  printf( "Default granularity is: %d (%s)\n", tmp,
113  stringify_granularity( tmp ) );
114  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
115  printf
116  ( "-------------------------------------------------------------------------\n" );
117 
118  printf( "Test type : \t1\t\t2\t\t3\t\t4\t\t5\n" );
119  sprintf( add_event_str, "%s : ", event_name );
120  printf( TAB5, add_event_str,
121  ( values[0] )[0], ( values[1] )[0], ( values[2] )[0],
122  ( values[3] )[0], ( values[4] )[0] );
123  printf( TAB5, "PAPI_TOT_CYC: ", ( values[0] )[1], ( values[1] )[1],
124  ( values[2] )[1], ( values[3] )[1], ( values[4] )[1] );
125  printf
126  ( "-------------------------------------------------------------------------\n" );
127 
128  printf( "Verification:\n" );
129  printf( "Column 1 approximately equals column 2\n" );
130  printf( "Column 3 approximately equals 2 * column 2\n" );
131  printf( "Column 4 approximately equals 3 * column 2\n" );
132  printf( "Column 4 exactly equals column 5\n" );
133  }
134 
135  {
136  long long min, max;
137  min = ( long long ) ( values[1][0] * .9 );
138  max = ( long long ) ( values[1][0] * 1.1 );
139 
140  if ( values[0][0] > max || values[0][0] < min ||
141  values[2][0] > ( 2 * max )
142  || values[2][0] < ( 2 * min ) || values[3][0] > ( 3 * max )
143  || values[3][0] < ( 3 * min )
144  || values[3][0] != values[4][0] ) {
145  printf( "min: " );
146  printf( LLDFMT, min );
147  printf( "max: " );
148  printf( LLDFMT, max );
149  printf( "1st: " );
150  printf( LLDFMT, values[0][0] );
151  printf( "2nd: " );
152  printf( LLDFMT, values[1][0] );
153  printf( "3rd: " );
154  printf( LLDFMT, values[2][0] );
155  printf( "4th: " );
156  printf( LLDFMT, values[3][0] );
157  printf( "5th: " );
158  printf( LLDFMT, values[4][0] );
159  printf( "\n" );
160  test_fail( __FILE__, __LINE__, event_name, 1 );
161  }
162 
163  min = ( long long ) ( values[1][1] * .9 );
164  max = ( long long ) ( values[1][1] * 1.1 );
165  if ( values[0][1] > max || values[0][1] < min ||
166  values[2][1] > ( 2 * max )
167  || values[2][1] < ( 2 * min ) || values[3][1] > ( 3 * max )
168  || values[3][1] < ( 3 * min )
169  || values[3][1] != values[4][1] ) {
170  test_fail( __FILE__, __LINE__, "PAPI_TOT_CYC", 1 );
171  }
172  }
173  test_pass( __FILE__, values, num_tests );
174 
175  MPI_Finalize( );
176  exit( 1 );
177 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int PAPI_event[2]
Definition: data_range.c:30
off64_t max
Definition: libasync.c:331
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_reset(int EventSet)
Definition: papi.c:2459
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define PAPI_NULL
Definition: papi.h:292
static int num_events
#define PAPI_TOT_INS
int EventSet
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
char ** argv
Definition: iozone.c:1610
#define MASK_FP_INS
Definition: papi_test.h:38
int PAPI_library_init(int version)
Definition: papi.c:500
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
int quiet
Definition: rapl_overflow.c:18
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
#define TAB5
Definition: papi_test.h:92
#define PAPI_DEFGRN
Definition: papi.h:434
long long
Definition: iozone.c:19827
#define min(x, y)
Definition: darwin-common.h:4
#define MASK_TOT_CYC
Definition: papi_test.h:40
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:915
int num_tests
Definition: zero_fork.c:53
void do_flops(int n)
Definition: multiplex.c:23
int PAPI_query_event(int EventCode)
Definition: papi.c:684
#define LLDFMT
Definition: papi_test.h:94
#define MASK_TOT_INS
Definition: papi_test.h:39
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
#define PAPI_DEFDOM
Definition: papi.h:432
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_read(int EventSet, long long *values)
Definition: papi.c:2559
int PAPI_start(int EventSet)
Definition: papi.c:2096
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:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
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:201
int add_test_events(int *number, int *mask, int allow_derived)
Definition: test_utils.c:152
#define PAPI_FP_INS