PAPI 7.1.0.0
Loading...
Searching...
No Matches
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
19int
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
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;
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;
51 options.granularity.granularity = PAPI_GRN_SYS_CPU;
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
66 exit( 1 );
67
69 exit( 1 );
70
72
74
76 if ( retval != PAPI_OK )
77 exit( 1 );
78
79 sleep( 5 );
80
82 if ( retval != PAPI_OK )
83 exit( 1 );
84
86
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}
int i
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Get PAPI library or event set options.
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
initialize the PAPI library.
Set PAPI library or event set options.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_DOM_USER
Definition: f90papi.h:174
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_DOM_OTHER
Definition: f90papi.h:21
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_GRANUL
Definition: f90papi.h:179
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_DOM_KERNEL
Definition: f90papi.h:254
#define PAPI_DOMAIN
Definition: f90papi.h:159
#define PAPI_MAX_HWCTRS
Definition: f90papi.h:270
#define PAPI_TOT_INS
Definition: f90papi.h:317
#define PAPI_GRN_SYS_CPU
Definition: f90papi.h:100
#define PAPI_MAX_CPUS
Definition: f90papi.h:119
#define PAPI_DOM_ALL
Definition: f90papi.h:261
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
FILE * stderr
static options_t options
int main()
Definition: pernode.c:20
A pointer to the following is passed to PAPI_set/get_opt()
Definition: papi.h:843
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53