/[escript]/trunk/paso/src/performance.c
ViewVC logotype

Contents of /trunk/paso/src/performance.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 495 - (show annotations)
Mon Feb 6 06:32:06 2006 UTC (15 years, 7 months ago) by gross
File MIME type: text/plain
File size: 7577 byte(s)
performance monitoring added. complies without PAPI.
1 /* $Id$ */
2
3 /**************************************************************/
4
5 /* Paso: perfomance monitor interface using papi */
6
7 /**************************************************************/
8
9 /* Copyrights by ACcESS Australia 2006 */
10 /* Author: gross@access.edu.au */
11
12 /**************************************************************/
13
14 #include "Paso.h"
15 #include "performance.h"
16
17 /* */
18 /* sets up the the monitoring process */
19 /* */
20 void Performance_open(Paso_Performance* pp) {
21 #ifdef PAPI
22 #pragma omp master
23 {
24 /* Initialize the PAPI library */
25 int retval = PAPI_library_init(PAPI_VER_CURRENT);
26 if (retval != PAPI_VER_CURRENT && retval > 0) {
27 Paso_setError(SYSTEM_ERROR,"Paso_performance: PAPI library version mismatch.");
28 return
29 }
30 if (retval < 0) {
31 Paso_setError(SYSTEM_ERROR,"Paso_performance: PAPI initialization error.");
32 return
33 }
34 /* Create an EventSet */
35 if (PAPI_create_eventset(&(pp->event_set)) != PAPI_OK) {
36 Paso_setError(SYSTEM_ERROR,"Paso_performance: PAPI event set set upo failed.");
37 return
38 }
39 /* try to add various monitors */
40 pp->num_events=0;
41 if (PAPI_add_event(pp->event_set, PAPI_FP_OPS) == PAPI_OK) {
42 pp->events[pp->num_events]=PAPI_FP_OPS;
43 pp->num_events++;
44 }
45 if (PAPI_add_event(pp->event_set, PAPI_L1_DCM) == PAPI_OK) {
46 pp->events[pp->num_events]=PAPI_L1_DCM;
47 pp->num_events++;
48 }
49 if (PAPI_add_event(pp->event_set, PAPI_L2_DCM) == PAPI_OK) {
50 pp->events[pp->num_events]=PAPI_L2_DCM;
51 pp->num_events++;
52 }
53 if (PAPI_add_event(pp->event_set, PAPI_L3_DCM) == PAPI_OK) {
54 pp->events[pp->num_events]=PAPI_L3_DCM;
55 pp->num_events++;
56 }
57 for (i=0;i<PERFORMANCE_NUM_MONITORS;++i) {
58 pp->cycles[i]=0;
59 pp->set[i]=PERFORMANCE_NOT_USED;
60 for (j=0;j<PERFORMANCE_NUM_EVENTS;++j) pp->values[i][j]=0.;
61 }
62 PAPI_start(pp->event_set);
63 }
64 #endif
65 }
66 /* find the index of an event in the list of monitored events */
67 int Performance_getEventIndex(Paso_Performance* pp, int event_id) {
68 #ifdef PAPI
69 int i;
70 for (i=0;i<pp->num_events;++i)
71 if (pp->events[i]==event_id) return i;
72 #endif
73 return PERFORMANCE_UNMONITORED_EVENT;
74 }
75 /* */
76 /* shuts down the monitoring process */
77 /* */
78 void Performance_close(Paso_Performance* pp) {
79 #ifdef PAPI
80 #pragma omp master
81 {
82 #ifdef SHOW_PERFORMANCE
83 int i;
84 int i_ops=Performance_getEventIndex(pp,PAPI_FP_OPS);
85 int i_l1_miss=Performance_getEventIndex(pp,PAPI_L1_DCM);
86 int i_l2_miss=Performance_getEventIndex(pp,PAPI_L2_DCM);
87 int i_l3_miss=Performance_getEventIndex(pp,PAPI_L3_DCM);
88 printf(" monitor |");
89 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT) printf(" flops/cycle |")
90 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l1_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L1 miss/flops |")
91 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l2_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L2 miss/flops |")
92 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l3_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L3 miss/flops |")
93 printf("\n");
94 for (i=0;i<PERFORMANCE_NUM_MONITORS;++i) {
95 if (! pp->set[i]==PERFORMANCE_NOT_USED ) {
96 swtich(i) {
97 case PERFORMANCE_ALL:
98 printf(" over all |");
99 break;
100 case PERFORMANCE_SOLVER:
101 printf(" solver |");
102 break;
103 case PERFORMANCE_PRECONDITIONER_INIT:
104 printf(" init. preconditioner |");
105 break;
106 case PERFORMANCE_PRECONDITIONER:
107 printf(" preconditioner |");
108 break;
109 case PERFORMANCE_MVM:
110 printf(" matrix-vector product |");
111 break;
112 case PERFORMANCE_ASSEMBLAGE:
113 printf(" assemblage |");
114 break;
115 default:
116 printf(" no name |");
117 break;
118 }
119 if (pp->set[i]==PERFORMANCE_CLOSED ) {
120 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT) printf(" %e12.5 |"%(((double)(pp->values[i][i_ops]))/((double)(pp->cycles[i]))));
121 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l1_miss!=PERFORMANCE_UNMONITORED_EVENT)
122 printf(" %e13.5 |"%(((double)(pp->values[i][i_l1_miss]))/((double)(pp->values[i][i_ops]))));
123 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l2_miss!=PERFORMANCE_UNMONITORED_EVENT)
124 printf(" %e13.5 |"%(((double)(pp->values[i][i_l2_miss]))/((double)(pp->values[i][i_ops]))));
125 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l3_miss!=PERFORMANCE_UNMONITORED_EVENT)
126 printf(" %e13.5 |"%(((double)(pp->values[i][i_l3_miss]))/((double)(pp->values[i][i_ops]))));
127 } else {
128 printf("not closed!!!");
129 }
130 printf("\n");
131 }
132 }
133 #endif
134 PAPI_cleanup_eventset(pp->event_set);
135 PAPI_destroy_eventset(pp->event_set);
136 }
137 #endif
138 }
139 /* */
140 /* switches on a monitor */
141 /* */
142 void Performance_startMonitor(Paso_Performance* pp,int monitor) {
143 #ifdef PAPI
144 long_long values[PERFORMANCE_NUM_EVENTS];
145 #pragma omp barrier
146 #pragma omp master
147 {
148 /* Start counting events in the Event Set */
149 PAPI_read(pp->event_set,values);
150 for (i=0;i<pp->num_events;++i) pp->values[monitor]-=values[i]
151 /* set cycles */
152 pp->cycles[monitor]-=PAPI_get_real_cyc();
153 pp->set[monitor]=PERFORMANCE_OPEN;
154 }
155 #endif
156 }
157 /* */
158 /* switches off a monitor */
159 /* */
160 void Performance_stopMonitor(Paso_Performance* pp,int monitor) {
161 #ifdef PAPI
162 long_long values[PERFORMANCE_NUM_EVENTS];
163 #pragma omp barrier
164 #pragma omp master
165 {
166 /* Add the counters in the Event Set */
167 PAPI_read(pp->event_set,values);
168 for (i=0;i<pp->num_events;++i) pp->values[monitor]+=values[i]
169 /* set cycles */
170 pp->cycles[monitor]+=PAPI_get_real_cyc();
171 pp->set[monitor]=PERFORMANCE_CLOSE;
172 }
173 #endif
174 }
175 /*
176 * $Log$
177 */
178

  ViewVC Help
Powered by ViewVC 1.1.26