PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
cpi.c File Reference
Include dependency graph for cpi.c:

Go to the source code of this file.

Functions

double f (double a)
 
int main (int argc, char **argv)
 

Variables

int TESTS_QUIET
 
char * netevents []
 

Function Documentation

double f ( double  a)

Definition at line 23 of file cpi.c.

24 {
25  return ( 4.0 / ( 1.0 + a * a ) );
26 }
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file cpi.c.

30 {
32  int evtcode;
33  int retval, i, ins = 0;
34  long long g1[2], g2[2];
35 
36  int done = 0, n, myid, numprocs;
37  double PI25DT = 3.141592653589793238462643;
38  double mypi, pi, h, sum, x;
39  double startwtime = 0.0, endwtime;
40  int namelen;
41  char processor_name[MPI_MAX_PROCESSOR_NAME];
42 
43  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
44 
45  if ( ( retval =
47  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
48 
49  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
50  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
51 
52  if ( ( retval = PAPI_create_eventset( &EventSet1 ) ) != PAPI_OK )
53  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
54 
55  PAPI_event_name_to_code( netevents[2], &evtcode );
56  if ( ( retval = PAPI_query_event( evtcode ) ) != PAPI_OK ) {
57  if ( retval != PAPI_ECNFLCT )
58  test_fail( __FILE__, __LINE__, "PAPI_aquery_event", retval );
59  }
60  if ( ( retval = PAPI_add_event( EventSet, evtcode ) ) != PAPI_OK ) {
61  if ( retval != PAPI_ECNFLCT )
62  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
63  }
64 
65  PAPI_event_name_to_code( netevents[3], &evtcode );
66  if ( ( retval = PAPI_query_event( evtcode ) ) != PAPI_OK ) {
67  if ( retval != PAPI_ECNFLCT )
68  test_fail( __FILE__, __LINE__, "PAPI_aquery_event", retval );
69  }
70  if ( ( retval = PAPI_add_event( EventSet, evtcode ) ) != PAPI_OK ) {
71  if ( retval != PAPI_ECNFLCT )
72  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
73  }
74 
75  if ( ( retval = PAPI_query_event( PAPI_FP_INS ) ) != PAPI_OK ) {
76  if ( ( retval = PAPI_query_event( PAPI_FP_OPS ) ) == PAPI_OK ) {
77  ins = 2;
78  if ( ( retval =
79  PAPI_add_event( EventSet1, PAPI_FP_OPS ) ) != PAPI_OK ) {
80  if ( retval != PAPI_ECNFLCT )
81  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
82  }
83  }
84  } else {
85  ins = 1;
86  if ( ( retval = PAPI_add_event( EventSet1, PAPI_FP_INS ) ) != PAPI_OK ) {
87  if ( retval != PAPI_ECNFLCT )
88  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
89  }
90  }
91 
92  if ( ( retval = PAPI_add_event( EventSet1, PAPI_TOT_CYC ) ) != PAPI_OK ) {
93  if ( retval != PAPI_ECNFLCT )
94  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
95  }
96 
97  MPI_Init( &argc, &argv );
98 
99  MPI_Comm_size( MPI_COMM_WORLD, &numprocs );
100  MPI_Comm_rank( MPI_COMM_WORLD, &myid );
101  MPI_Get_processor_name( processor_name, &namelen );
102 
103  fprintf( stdout, "Process %d of %d on %s\n",
104  myid, numprocs, processor_name );
105  fflush( stdout );
106 
107  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
108  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
109 
110  if ( ( retval = PAPI_start( EventSet1 ) ) != PAPI_OK )
111  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
112 
113  n = 0;
114  while ( !done ) {
115  if ( myid == 0 ) {
116  if ( n == 0 )
117  n = 1000000;
118  else
119  n = 0;
120 
121  startwtime = MPI_Wtime( );
122  }
123  MPI_Bcast( &n, 1, MPI_INT, 0, MPI_COMM_WORLD );
124  if ( n == 0 )
125  done = 1;
126  else {
127  h = 1.0 / ( double ) n;
128  sum = 0.0;
129  /* A slightly better approach starts from large i and works back */
130  for ( i = myid + 1; i <= n; i += numprocs ) {
131  x = h * ( ( double ) i - 0.5 );
132  sum += f( x );
133  }
134  mypi = h * sum;
135 
136  MPI_Reduce( &mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD );
137 
138  if ( myid == 0 ) {
139  printf( "pi is approximately %.16f, Error is %.16f\n",
140  pi, fabs( pi - PI25DT ) );
141  endwtime = MPI_Wtime( );
142  printf( "wall clock time = %f\n", endwtime - startwtime );
143  fflush( stdout );
144  }
145  }
146  }
147 
148  if ( ( retval = PAPI_stop( EventSet1, g1 ) ) != PAPI_OK )
149  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
150 
151  if ( ( retval = PAPI_stop( EventSet, g2 ) ) != PAPI_OK )
152  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
153 
154  MPI_Finalize( );
155 
156 
157  printf( "ETH0_RX_BYTES: %lld ETH0_TX_BYTES: %lld\n", g2[0], g2[1] );
158  if ( ins == 0 ) {
159  printf( "PAPI_TOT_CYC : %lld\n", g1[0] );
160  } else if ( ins == 1 ) {
161  printf( "PAPI_FP_INS : %lld PAPI_TOT_CYC : %lld\n", g1[0], g1[1] );
162  } else if ( ins == 2 ) {
163  printf( "PAPI_FP_OPS : %lld PAPI_TOT_CYC : %lld\n", g1[0], g1[1] );
164  }
165  test_pass( __FILE__, NULL, 0 );
166  return 0;
167 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
double f(double a)
Definition: cpi.c:23
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
#define PAPI_NULL
Definition: fpapi.h:13
long long myid
Definition: iozone.c:1335
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_FP_OPS
Definition: fpapi.h:237
tests_quiet(argc, argv)
fflush(stdout)
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
#define PAPI_ECNFLCT
Definition: fpapi.h:113
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_TOT_CYC
Definition: fpapi.h:194
char * netevents[]
Definition: cpi.c:19
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_FP_INS
Definition: fpapi.h:187
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1003
int PAPI_query_event(int EventCode)
Definition: papi.c:695
int EventSet
int x
Definition: fileop.c:78
int PAPI_start(int EventSet)
Definition: papi.c:2019
ssize_t retval
Definition: libasync.c:338
int EventSet1
Definition: zero_fork.c:40
int n
Definition: mendes-alt.c:164
FILE * pi
Definition: iozone.c:1367

Here is the call graph for this function:

Variable Documentation

char* netevents[]
Initial value:
=
{ "LO_RX_PACKETS", "LO_TX_PACKETS", "ETH0_RX_PACKETS", "ETH0_TX_PACKETS" }

Definition at line 19 of file cpi.c.

int TESTS_QUIET

Definition at line 11 of file test_utils.c.