PAPI  5.3.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pernode.c
Go to the documentation of this file.
1 /* This file performs the following test:
2 
3  - make an event set with PAPI_TOT_INS and PAPI_TOT_CYC.
4  - enable per node counting
5  - enable full domain counting
6  - sleeps for 5 seconds
7  - print the results
8 */
9 
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include <sys/types.h>
15 #include <memory.h>
16 #include <malloc.h>
17 #include "papi_test.h"
18 
19 int
20 main( )
21 {
22  int ncpu, nctr, i, actual_domain;
23  int retval;
24  int EventSet = PAPI_NULL;
25  long long *values;
26  long long elapsed_us, elapsed_cyc;
28 
30  if ( retval != PAPI_VER_CURRENT ) {
31  fprintf( stderr, "Library mismatch: code %d, library %d\n", retval,
33  exit( 1 );
34  }
35 
36  if ( PAPI_create_eventset( &EventSet ) != PAPI_OK )
37  exit( 1 );
38 
39  /* Set the domain as high as it will go. */
40 
41  options.domain.eventset = EventSet;
42  options.domain.domain = PAPI_DOM_ALL;
43  retval = PAPI_set_opt( PAPI_DOMAIN, &options );
44  if ( retval != PAPI_OK )
45  exit( 1 );
46  actual_domain = options.domain.domain;
47 
48  /* This should only happen to an empty eventset */
49 
50  options.granularity.eventset = EventSet;
52  retval = PAPI_set_opt( PAPI_GRANUL, &options );
53  if ( retval != PAPI_OK )
54  exit( 1 );
55 
56  /* Malloc the output array */
57 
58  ncpu = PAPI_get_opt( PAPI_MAX_CPUS, NULL );
59  nctr = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL );
60  values = ( long long * ) malloc( ncpu * nctr * sizeof ( long long ) );
61  memset( values, 0x0, ( ncpu * nctr * sizeof ( long long ) ) );
62 
63  /* Add the counters */
64 
65  if ( PAPI_add_event( EventSet, PAPI_TOT_CYC ) != PAPI_OK )
66  exit( 1 );
67 
68  if ( PAPI_add_event( EventSet, PAPI_TOT_INS ) != PAPI_OK )
69  exit( 1 );
70 
71  elapsed_us = PAPI_get_real_usec( );
72 
73  elapsed_cyc = PAPI_get_real_cyc( );
74 
75  retval = PAPI_start( EventSet );
76  if ( retval != PAPI_OK )
77  exit( 1 );
78 
79  sleep( 5 );
80 
81  retval = PAPI_stop( EventSet, values );
82  if ( retval != PAPI_OK )
83  exit( 1 );
84 
85  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
86 
87  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
88 
89  printf( "Test case: per node\n" );
90  printf( "-------------------\n\n" );
91 
92  printf( "This machine has %d cpus, each with %d counters.\n", ncpu, nctr );
93  printf( "Test case asked for: PAPI_DOM_ALL\n" );
94  printf( "Test case got: " );
95  if ( actual_domain & PAPI_DOM_USER )
96  printf( "PAPI_DOM_USER " );
97  if ( actual_domain & PAPI_DOM_KERNEL )
98  printf( "PAPI_DOM_KERNEL " );
99  if ( actual_domain & PAPI_DOM_OTHER )
100  printf( "PAPI_DOM_OTHER " );
101  printf( "\n" );
102 
103  for ( i = 0; i < ncpu; i++ ) {
104  printf( "CPU %d\n", i );
105  printf( "PAPI_TOT_CYC: \t%lld\n", values[0 + i * nctr] );
106  printf( "PAPI_TOT_INS: \t%lld\n", values[1 + i * nctr] );
107  }
108 
109  printf
110  ( "\n-------------------------------------------------------------------------\n" );
111 
112  printf( "Real usec : \t%lld\n", elapsed_us );
113  printf( "Real cycles : \t%lld\n", elapsed_cyc );
114 
115  printf
116  ( "-------------------------------------------------------------------------\n" );
117 
118  free( values );
119 
120  PAPI_shutdown( );
121 
122  exit( 0 );
123 }
memset(eventId, 0, size)
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define PAPI_GRN_SYS_CPU
Definition: fpapi.h:72
sleep(1)
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
#define PAPI_NULL
Definition: fpapi.h:13
#define PAPI_DOM_ALL
Definition: fpapi.h:25
#define PAPI_TOT_INS
Definition: fpapi.h:185
PAPI_granularity_option_t granularity
Definition: papi.h:848
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_DOM_OTHER
Definition: fpapi.h:23
#define PAPI_DOM_KERNEL
Definition: fpapi.h:22
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
#define printf
Definition: papi_test.h:125
int PAPI_set_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:3360
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_MAX_HWCTRS
Definition: fpapi.h:58
#define PAPI_TOT_CYC
Definition: fpapi.h:194
void PAPI_shutdown(void)
Definition: papi.c:4344
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4030
long long elapsed_cyc
Definition: zero_fork.c:43
free(dummyfile[xx])
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_DOMAIN
Definition: fpapi.h:50
#define PAPI_GRANUL
Definition: fpapi.h:52
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
int EventSet
long long PAPI_get_real_usec(void)
Definition: papi.c:6125
PAPI_domain_option_t domain
Definition: papi.h:850
long long PAPI_get_real_cyc(void)
Definition: papi.c:6078
#define PAPI_DOM_USER
Definition: fpapi.h:21
int PAPI_start(int EventSet)
Definition: papi.c:2019
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long elapsed_us
Definition: zero_fork.c:43
static options_t options
int main(int argc, char **argv)
List all appio events codes and names.
void exit()
#define PAPI_MAX_CPUS
Definition: fpapi.h:61