PAPI 7.1.0.0
Loading...
Searching...
No Matches
multiplex.c
Go to the documentation of this file.
1/****************************************************************************
2 * Multiplexing allows more counters to be used than what is supported by *
3 * the platform, thus allowing a larger number of events to be counted *
4 * simultaneously. When a microprocessor has a very limited number of *
5 * counters that can be counted simultaneously, a large application with *
6 * many hours of run time may require days of profiling in order to gather *
7 * enough information to base a performance analysis. Multiplexing overcomes*
8 * this limitation by the usage of the counters over timesharing. *
9 * This is an example demonstrating how to use PAPI_set_multiplex to *
10 * convert a standard event set to a multiplexed event set. *
11 ****************************************************************************/
12#include <stdlib.h>
13#include <stdio.h>
14#include <unistd.h>
15#include "papi.h"
16
17#define ERROR_RETURN(retval) { fprintf(stderr, "Error %d %s:line %d: \n", retval,__FILE__,__LINE__); exit(retval); }
18
19#define NUM_ITERS 10000000
20#define MAX_TO_ADD 6
21
22double c = 0.11;
23void do_flops(int n)
24{
25 int i;
26 double a = 0.5;
27 double b = 6.2;
28
29 for (i=0; i < n; i++)
30 c += a * b;
31 return;
32}
33
34/* Tests that we can really multiplex a lot. */
35int multiplex(void)
36{
37 int retval, i, EventSet = PAPI_NULL, j = 0;
38 long long *values;
40 int events[MAX_TO_ADD], number;
41
42 /* Initialize the library */
45 {
46 printf("Library initialization error! \n");
47 exit(1);
48 }
49
50 /* initialize multiplex support */
52 if (retval != PAPI_OK)
54
56 if (retval != PAPI_OK)
58
59 /* convert the event set to a multiplex event set */
61 if (retval != PAPI_OK)
63/*
64 retval = PAPI_add_event(EventSet, PAPI_TOT_INS);
65 if ((retval != PAPI_OK) && (retval != PAPI_ECNFLCT))
66 ERROR_RETURN(retval);
67 printf("Adding %s\n", "PAPI_TOT_INS");
68*/
69
70 for (i = 0; i < PAPI_MAX_PRESET_EVENTS; i++)
71 {
73 if (retval != PAPI_OK)
75
76 if ((pset.count) && (pset.event_code != PAPI_TOT_CYC))
77 {
78 printf("Adding %s\n", pset.symbol);
79
81 if ((retval != PAPI_OK) && (retval != PAPI_ECNFLCT))
83
84 if (retval == PAPI_OK)
85 printf("Added %s\n", pset.symbol);
86 else
87 printf("Could not add %s due to resource limitation.\n",
88 pset.symbol);
89
90 if (retval == PAPI_OK)
91 {
92 if (++j >= MAX_TO_ADD)
93 break;
94 }
95 }
96 }
97
98 values = (long long *) malloc(MAX_TO_ADD * sizeof(long long));
99 if (values == NULL)
100 {
101 printf("Not enough memory available. \n");
102 exit(1);
103 }
104
107
109
111 if (retval != PAPI_OK)
113
114 /* get the number of events in the event set */
115 number=MAX_TO_ADD;
116 if ( (retval = PAPI_list_events(EventSet, events, &number)) != PAPI_OK)
118
119 /* print the read result */
120 for (i = 0; i < MAX_TO_ADD; i++)
121 {
123 if (retval != PAPI_OK)
125 printf("Event name: %s value: %lld \n", pset.symbol, values[i]);
126 }
127
129 if (retval != PAPI_OK)
131
133 if (retval != PAPI_OK)
135
136 /* free the resources used by PAPI */
138
139 return (0);
140}
141
142int main(int argc, char **argv)
143{
144
145 printf("Using %d iterations\n\n", NUM_ITERS);
146 printf("Does PAPI_multiplex_init() handle lots of events?\n");
147 multiplex();
148 exit(0);
149}
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Get the event's name and description info.
initialize the PAPI library.
list the events in an event set
Initialize multiplex support in the PAPI library.
Convert a standard event set to a multiplexed event set.
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_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ECNFLCT
Definition: f90papi.h:234
char events[MAX_EVENTS][BUFSIZ]
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
void do_flops(int n)
Definition: multiplex.c:23
#define MAX_TO_ADD
Definition: multiplex.c:20
double c
Definition: multiplex.c:22
#define NUM_ITERS
Definition: multiplex.c:19
#define ERROR_RETURN(retval)
Definition: multiplex.c:17
int multiplex(void)
Definition: multiplex.c:35
#define PAPI_PRESET_MASK
#define PAPI_MAX_PRESET_EVENTS
Return codes and api definitions.
int main()
Definition: pernode.c:20
unsigned int count
Definition: papi.h:981
unsigned int event_code
Definition: papi.h:958
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
int retval
Definition: zero_fork.c:53