PAPI 7.1.0.0
Loading...
Searching...
No Matches
clockcore.c File Reference
Include dependency graph for clockcore.c:

Go to the source code of this file.

Macros

#define NUM_ITERS   1000000
 

Functions

static int clock_res_check (int flag, int quiet)
 
int clockcore (int quiet)
 

Variables

static char * func_name []
 
static int CLOCK_ERROR = 0
 

Macro Definition Documentation

◆ NUM_ITERS

#define NUM_ITERS   1000000

Definition at line 9 of file clockcore.c.

Function Documentation

◆ clock_res_check()

static int clock_res_check ( int  flag,
int  quiet 
)
static

Definition at line 20 of file clockcore.c.

21{
22 if ( CLOCK_ERROR ) {
23 return -1;
24 }
25
26 long long *elapsed_cyc, total_cyc = 0, uniq_cyc = 0, diff_cyc = 0;
27 int i;
28 double min, max, average, std, tmp;
29
30 elapsed_cyc = ( long long * ) calloc( NUM_ITERS, sizeof ( long long ) );
31
32 /* Real */
33 switch ( flag ) {
34 case 0:
35 for ( i = 0; i < NUM_ITERS; i++ )
36 elapsed_cyc[i] = ( long long ) PAPI_get_real_cyc( );
37 break;
38 case 1:
39 for ( i = 0; i < NUM_ITERS; i++ )
40 elapsed_cyc[i] = ( long long ) PAPI_get_real_usec( );
41 break;
42 case 2:
43 for ( i = 0; i < NUM_ITERS; i++ )
44 elapsed_cyc[i] = ( long long ) PAPI_get_virt_cyc( );
45 break;
46 case 3:
47 for ( i = 0; i < NUM_ITERS; i++ )
48 elapsed_cyc[i] = ( long long ) PAPI_get_virt_usec( );
49 break;
50 default:
51 free(elapsed_cyc);
52 return -1;
53
54 }
55
56 min = max = ( double ) ( elapsed_cyc[1] - elapsed_cyc[0] );
57
58 for ( i = 1; i < NUM_ITERS; i++ ) {
59 if ( elapsed_cyc[i] - elapsed_cyc[i - 1] < 0 ) {
60 CLOCK_ERROR = 1;
61 fprintf(stderr,"Error! Negative elapsed time\n");
62 free( elapsed_cyc );
63 return -1;
64 }
65
66 diff_cyc = elapsed_cyc[i] - elapsed_cyc[i - 1];
67 if ( min > diff_cyc )
68 min = ( double ) diff_cyc;
69 if ( max < diff_cyc )
70 max = ( double ) diff_cyc;
71 if ( diff_cyc != 0 )
72 uniq_cyc++;
73 total_cyc += diff_cyc;
74 }
75
76 average = ( double ) total_cyc / ( NUM_ITERS - 1 );
77 std = 0;
78
79 for ( i = 1; i < NUM_ITERS; i++ ) {
80 tmp = ( double ) ( elapsed_cyc[i] - elapsed_cyc[i - 1] );
81 tmp = tmp - average;
82 std += tmp * tmp;
83 }
84
85 if ( !quiet ) {
86 std = sqrt( std / ( NUM_ITERS - 2 ) );
87 printf( "%s: min %.3lf max %.3lf \n", func_name[flag], min, max );
88 printf( " average %.3lf std %.3lf\n", average, std );
89
90 if ( uniq_cyc == NUM_ITERS - 1 ) {
91 printf( "%s : %7.3f <%7.3f\n", func_name[flag],
92 ( double ) total_cyc / ( double ) ( NUM_ITERS ),
93 ( double ) total_cyc / ( double ) uniq_cyc );
94 } else if ( uniq_cyc ) {
95 printf( "%s : %7.3f %7.3f\n", func_name[flag],
96 ( double ) total_cyc / ( double ) ( NUM_ITERS ),
97 ( double ) total_cyc / ( double ) uniq_cyc );
98 } else {
99 printf( "%s : %7.3f >%7.3f\n", func_name[flag],
100 ( double ) total_cyc / ( double ) ( NUM_ITERS ),
101 ( double ) total_cyc );
102 }
103 }
104
105 free( elapsed_cyc );
106
107 return PAPI_OK;
108}
double tmp
int i
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
get virtual time counter value in clock cycles
get virtual time counter values in microseconds
#define NUM_ITERS
Definition: clockcore.c:9
static char * func_name[]
Definition: clockcore.c:11
static int CLOCK_ERROR
Definition: clockcore.c:17
#define min(x, y)
Definition: darwin-common.h:4
#define PAPI_OK
Definition: f90papi.h:73
FILE * stderr
int quiet
Definition: rapl_overflow.c:19
long long elapsed_cyc
Definition: zero_fork.c:50
Here is the caller graph for this function:

◆ clockcore()

int clockcore ( int  quiet)

Definition at line 111 of file clockcore.c.

112{
113 /* check PAPI_get_real_cyc */
115 /* check PAPI_get_real_usec */
117
118 /* check PAPI_get_virt_cyc */
119 /* Virtual */
120 if ( PAPI_get_virt_cyc( ) != -1 ) {
122 } else {
124 }
125
126 /* check PAPI_get_virt_usec */
127 if ( PAPI_get_virt_usec( ) != -1 ) {
129 } else {
131 }
132
133 return PAPI_OK;
134}
static int clock_res_check(int flag, int quiet)
Definition: clockcore.c:20
#define CLOCKCORE_VIRT_USEC_FAIL
Definition: clockcore.h:2
#define CLOCKCORE_VIRT_CYC_FAIL
Definition: clockcore.h:1
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ CLOCK_ERROR

int CLOCK_ERROR = 0
static

Definition at line 17 of file clockcore.c.

◆ func_name

char* func_name[]
static
Initial value:
= {
"PAPI_get_real_cyc",
"PAPI_get_real_usec",
"PAPI_get_virt_cyc",
"PAPI_get_virt_usec"
}

Definition at line 11 of file clockcore.c.