PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ipc.c
Go to the documentation of this file.
1 /*
2  * A simple example for the use of PAPI, using PAPI_ipc
3  * -Kevin London
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include "papi.h"
10 #include "papi_test.h"
11 
12 
13 #define INDEX 500
14 
15 int
16 main( int argc, char **argv )
17 {
18  extern void dummy( void * );
19  float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX][INDEX];
20  float real_time, proc_time, ipc;
21  long long ins;
22  int retval;
23  int i, j, k;
24  int quiet;
25 
26  /* Set TESTS_QUIET variable */
27  quiet=tests_quiet( argc, argv );
28 
29  /* Initialize the Matrix arrays */
30  for( i = 0; i < INDEX; i++ ) {
31  for( j= 0; j < INDEX; j++ ) {
32  mresult[i][j] = 0.0;
33  matrixa[i][j] = matrixb[i][j] = ( float ) rand( ) * ( float ) 1.1;
34  }
35  }
36 
37  /* Setup PAPI library and begin collecting data from the counters */
38  retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc );
39  if (retval < PAPI_OK ) {
40  if (!quiet) printf("Trouble starting IPC\n");
41  test_skip( __FILE__, __LINE__, "PAPI_ipc", retval );
42  }
43 
44  /* Matrix-Matrix multiply */
45  for ( i = 0; i < INDEX; i++ )
46  for ( j = 0; j < INDEX; j++ )
47  for ( k = 0; k < INDEX; k++ )
48  mresult[i][j] = mresult[i][j] + matrixa[i][k] * matrixb[k][j];
49 
50  /* Collect the data into the variables passed in */
51  if ( ( retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc ) ) < PAPI_OK )
52  test_fail( __FILE__, __LINE__, "PAPI_ipc", retval );
53  dummy( ( void * ) mresult );
54 
55  if ( !quiet ) {
56  printf( "Real_time: %f Proc_time: %f Total ins: ", real_time,
57  proc_time );
58  printf( LLDFMT, ins );
59  printf( " IPC: %f\n", ipc );
60  }
61 
62  /* This should not happen unless the optimizer */
63  /* gets too good */
64  if (ins < INDEX*INDEX) {
65  test_fail( __FILE__, __LINE__, "Instruction count too low.",
66  5 );
67  }
68  /* Something is broken, or else you have a really */
69  /* slow processor */
70  if (ipc<0.01 ) {
71  test_fail( __FILE__, __LINE__, "IPC equals zero.",
72  5 );
73  }
74 
75  test_pass( __FILE__ );
76 
77  return 0;
78 }
void test_pass(const char *filename)
Definition: test_utils.c:432
#define INDEX
Definition: ipc.c:13
int PAPI_ipc(float *rtime, float *ptime, long long *ins, float *ipc)
Definition: papi_hl.c:316
return PAPI_OK
Definition: linux-nvml.c:497
int int argc
Definition: iozone.c:1609
int dummy
Definition: iozone.c:19741
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int i
Definition: fileop.c:140
int quiet
Definition: rapl_overflow.c:18
int k
Definition: iozone.c:19136
#define LLDFMT
Definition: papi_test.h:94
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
int rand()
long j
Definition: iozone.c:19135
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.