PAPI 7.1.0.0
Loading...
Searching...
No Matches
examples/sprofile.c File Reference
Include dependency graph for examples/sprofile.c:

Go to the source code of this file.

Macros

#define NUM_FLOPS   20000000
 
#define NUM_ITERS   100000
 
#define THRESHOLD   100000
 
#define ERROR_RETURN(retval)   { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
 
#define DO_FLOPS1   (vptr_t)(do_flops1)
 
#define DO_FLOPS2   (vptr_t)(do_flops2)
 

Functions

void do_flops2 (int)
 
void do_flops1 (int n)
 
void do_both (int n)
 
int main (int argc, char **argv)
 

Variables

volatile double t1 = 0.8
 
volatile double t2 = 0.9
 
volatile double a = 0.5
 
volatile double b = 2.2
 

Macro Definition Documentation

◆ DO_FLOPS1

#define DO_FLOPS1   (vptr_t)(do_flops1)

Definition at line 22 of file examples/sprofile.c.

◆ DO_FLOPS2

#define DO_FLOPS2   (vptr_t)(do_flops2)

Definition at line 23 of file examples/sprofile.c.

◆ ERROR_RETURN

#define ERROR_RETURN (   retval)    { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }

Definition at line 16 of file examples/sprofile.c.

◆ NUM_FLOPS

#define NUM_FLOPS   20000000

Definition at line 13 of file examples/sprofile.c.

◆ NUM_ITERS

#define NUM_ITERS   100000

Definition at line 14 of file examples/sprofile.c.

◆ THRESHOLD

#define THRESHOLD   100000

Definition at line 15 of file examples/sprofile.c.

Function Documentation

◆ do_both()

void do_both ( int  n)

Definition at line 37 of file examples/sprofile.c.

38{
39 int i;
40 const int flops2 = NUM_FLOPS / n;
41 const int flops1 = NUM_FLOPS / n;
42
43 for (i = 0; i < n; i++)
44 {
45 do_flops1(flops1);
46 do_flops2(flops2);
47 }
48}
int i
void do_flops1(int n)
void do_flops2(int)
#define NUM_FLOPS
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_flops1()

void do_flops1 ( int  n)

Definition at line 28 of file examples/sprofile.c.

29{
30 int i;
31 double c = 22222.11;
32
33 for (i = 0; i < n; i++)
34 c -= t1 * t2;
35}
volatile double t1
volatile double t2
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
Here is the caller graph for this function:

◆ do_flops2()

void do_flops2 ( int  n)

Definition at line 174 of file examples/sprofile.c.

175{
176 int i;
177 double c = 0.11;
178
179 for (i = 0; i < n; i++)
180 c += a * b;
181}
volatile double b
volatile double a
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 50 of file examples/sprofile.c.

51{
52 int i , PAPI_event;
53 int EventSet = PAPI_NULL;
54 unsigned short *profbuf;
55 unsigned short *profbuf2;
56 unsigned short *profbuf3;
57 unsigned long length;
58 vptr_t start, end;
59 long long values[2];
60 const PAPI_exe_info_t *prginfo = NULL;
61 PAPI_sprofil_t sprof[3];
62 int retval;
63
64 /* initializaion */
66 {
67 printf("Library initialization error! \n");
68 exit(1);
69 }
70
71 if ((prginfo = PAPI_get_executable_info()) == NULL)
72 ERROR_RETURN(1);
73
74 start = prginfo->address_info.text_start;
75 end = prginfo->address_info.text_end;
76 length = (end - start)/sizeof(unsigned short) * sizeof(unsigned short);
77 printf("start= %p end =%p \n", start, end);
78
79 profbuf = (unsigned short *) malloc(length);
80 if (profbuf == NULL)
82
83 memset(profbuf, 0x00, length );
84
85 profbuf2 = (unsigned short *) malloc(length);
86 if (profbuf2 == NULL)
88
89 memset(profbuf2, 0x00, length );
90
91 profbuf3 = (unsigned short *) malloc(1 * sizeof(unsigned short));
92 if (profbuf3 == NULL)
94
95 memset(profbuf3, 0x00, 1 * sizeof(unsigned short));
96
97 /* First half */
98 sprof[0].pr_base = profbuf;
99 sprof[0].pr_size = length / 2;
100 sprof[0].pr_off = DO_FLOPS2;
101 fprintf(stderr, "do_flops is at %p %lx\n", &do_flops2, strtoul(sprof[0].pr_off,NULL,0));
102
103 sprof[0].pr_scale = 65536; /* constant needed by PAPI_sprofil */
104 /* Second half */
105 sprof[1].pr_base = profbuf2;
106 sprof[1].pr_size = length / 2;
107 sprof[1].pr_off = DO_FLOPS1;
108 fprintf(stderr, "do_flops1 is at %p %lx\n", &do_flops1, strtoul(sprof[1].pr_off,NULL,0));
109 sprof[1].pr_scale = 65536; /* constant needed by PAPI_sprofil */
110
111 /* Overflow bin */
112 sprof[2].pr_base = profbuf3;
113 sprof[2].pr_size = 1;
114 sprof[2].pr_off = 0;
115 sprof[2].pr_scale = 0x2; /* constant needed by PAPI_sprofil */
116
117 /* Creating the eventset */
120
122 /* Add Total Instructions Executed to our EventSet */
125
126 /* Add Total Instructions Executed to our EventSet */
129
130 /* set profile flag */
134
135 if ((retval = PAPI_start(EventSet)) != PAPI_OK)
137
139
142
143 /* to clear the profile flag before removing the events */
144 if ((retval = PAPI_sprofil(sprof, 3, EventSet, PAPI_event, 0,
147
148 /* free the resources hold by PAPI */
150
151 printf("Test case: PAPI_sprofil()\n");
152 printf("---------Buffer 1--------\n");
153 for (i = 0; i < length / 2; i++)
154 {
155 if (profbuf[i])
156 printf("%#lx\t%d\n", strtoul(DO_FLOPS2,NULL,0) + 2 * i, profbuf[i]);
157 }
158 printf("---------Buffer 2--------\n");
159 for (i = 0; i < length / 2; i++)
160 {
161 if (profbuf2[i])
162 printf("%#lx\t%d\n", strtoul(DO_FLOPS1,NULL,0) + 2 * i, profbuf2[i]);
163 }
164 printf("-------------------------\n");
165 printf("%u samples fell outside the regions.\n", *profbuf3);
166
167 exit(0);
168}
add PAPI preset or native hardware event to an event set
Create a new empty PAPI EventSet.
Get the executable's address space info.
initialize the PAPI library.
Finish using PAPI and free all related resources.
Generate PC histogram data from multiple code regions where hardware counter overflow occurs.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
int PAPI_event[2]
Definition: data_range.c:30
#define DO_FLOPS2
#define THRESHOLD
#define NUM_ITERS
#define ERROR_RETURN(retval)
#define DO_FLOPS1
void do_both(int n)
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_PROFIL_POSIX
Definition: f90papi.h:44
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_TOT_INS
Definition: f90papi.h:317
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static struct timeval start
void * vptr_t
Definition: papi.h:576
FILE * stderr
void * profbuf[5]
Definition: prof_utils.c:33
unsigned int length
vptr_t text_start
Definition: papi.h:686
vptr_t text_end
Definition: papi.h:687
get the executable's info
Definition: papi.h:696
PAPI_address_map_t address_info
Definition: papi.h:698
vptr_t pr_off
Definition: papi.h:582
unsigned pr_size
Definition: papi.h:581
void * pr_base
Definition: papi.h:580
unsigned pr_scale
Definition: papi.h:583
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

Variable Documentation

◆ a

volatile double a = 0.5

Definition at line 173 of file examples/sprofile.c.

◆ b

volatile double b = 2.2

Definition at line 173 of file examples/sprofile.c.

◆ t1

volatile double t1 = 0.8

Definition at line 27 of file examples/sprofile.c.

◆ t2

volatile double t2 = 0.9

Definition at line 27 of file examples/sprofile.c.