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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3642 - (show annotations)
Thu Oct 27 03:41:51 2011 UTC (7 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 8199 byte(s)
Assorted spelling/comment fixes in paso.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Paso: performance monitor interface using papi */
18
19 /**************************************************************/
20
21 /* Copyrights by ACcESS Australia 2006 */
22 /* Author: Lutz Gross, l.gross@uq.edu.au */
23
24 /**************************************************************/
25
26 #include "Paso.h"
27 #include "performance.h"
28
29 /* */
30 /* sets up the monitoring process */
31 /* */
32 void Performance_open(Paso_Performance* pp,int verbose) {
33 #ifdef PAPI
34 int i,j;
35 #pragma omp single
36 {
37 pp->event_set=PAPI_NULL;
38 /* Initialize the PAPI library */
39 int retval = PAPI_library_init(PAPI_VER_CURRENT);
40 if (retval != PAPI_VER_CURRENT && retval > 0) {
41 Esys_setError(SYSTEM_ERROR,"Paso_performance: PAPI library version mismatch.");
42 } else if (retval < 0) {
43 Esys_setError(SYSTEM_ERROR,"Paso_performance: PAPI initialization error.");
44 } else {
45 if (PAPI_create_eventset(&(pp->event_set)) != PAPI_OK)
46 Esys_setError(SYSTEM_ERROR,"Paso_performance: PAPI event set up failed.");
47 }
48 if (Esys_noError()) {
49 /* try to add various monitors */
50 pp->num_events=0;
51 if (PAPI_add_event(pp->event_set, PAPI_FP_OPS) == PAPI_OK) {
52 pp->events[pp->num_events]=PAPI_FP_OPS;
53 pp->num_events++;
54 }
55 if (PAPI_add_event(pp->event_set, PAPI_L1_DCM) == PAPI_OK) {
56 pp->events[pp->num_events]=PAPI_L1_DCM;
57 pp->num_events++;
58 }
59 if (PAPI_add_event(pp->event_set, PAPI_L2_DCM) == PAPI_OK) {
60 pp->events[pp->num_events]=PAPI_L2_DCM;
61 pp->num_events++;
62 }
63 if (PAPI_add_event(pp->event_set, PAPI_L3_DCM) == PAPI_OK) {
64 pp->events[pp->num_events]=PAPI_L3_DCM;
65 pp->num_events++;
66 }
67 for (i=0;i<PERFORMANCE_NUM_MONITORS;++i) {
68 pp->cycles[i]=0;
69 pp->set[i]=PERFORMANCE_UNUSED;
70 for (j=0;j<PERFORMANCE_NUM_EVENTS;++j) pp->values[i][j]=0.;
71 }
72 PAPI_start(pp->event_set);
73 }
74 }
75 #endif
76 }
77
78 /* find the index of an event in the list of monitored events */
79 int Performance_getEventIndex(Paso_Performance* pp, int event_id) {
80 #ifdef PAPI
81 int i;
82 for (i=0;i<pp->num_events;++i)
83 if (pp->events[i]==event_id) return i;
84 #endif
85 return PERFORMANCE_UNMONITORED_EVENT;
86 }
87
88 /* */
89 /* shuts down the monitoring process */
90 /* */
91 void Performance_close(Paso_Performance* pp,int verbose) {
92 #ifdef PAPI
93 long_long values[PERFORMANCE_NUM_EVENTS];
94 #pragma omp single
95 {
96 if (Esys_noError() && verbose) {
97 int i;
98 int i_ops=Performance_getEventIndex(pp,PAPI_FP_OPS);
99 int i_l1_miss=Performance_getEventIndex(pp,PAPI_L1_DCM);
100 int i_l2_miss=Performance_getEventIndex(pp,PAPI_L2_DCM);
101 int i_l3_miss=Performance_getEventIndex(pp,PAPI_L3_DCM);
102 printf(" monitor |");
103 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT) printf(" flops/cycle |");
104 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l1_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L1 miss/flops |");
105 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l2_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L2 miss/flops |");
106 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l3_miss!=PERFORMANCE_UNMONITORED_EVENT) printf(" L3 miss/flops |");
107 printf("\n");
108 for (i=0;i<PERFORMANCE_NUM_MONITORS;++i) {
109 if (pp->set[i]!=PERFORMANCE_UNUSED ) {
110 switch(i) {
111 case PERFORMANCE_ALL:
112 printf(" over all |");
113 break;
114 case PERFORMANCE_SOLVER:
115 printf(" solver |");
116 break;
117 case PERFORMANCE_PRECONDITIONER_INIT:
118 printf(" init. preconditioner |");
119 break;
120 case PERFORMANCE_PRECONDITIONER:
121 printf(" preconditioner |");
122 break;
123 case PERFORMANCE_MVM:
124 printf(" matrix-vector product |");
125 break;
126 case PERFORMANCE_ASSEMBLAGE:
127 printf(" assemblage |");
128 break;
129 default:
130 printf(" no name |");
131 break;
132 }
133 if (pp->set[i]==PERFORMANCE_CLOSED ) {
134 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT) printf(" %12.5e |",(((double)(pp->values[i][i_ops]))/((double)(pp->cycles[i]))));
135 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l1_miss!=PERFORMANCE_UNMONITORED_EVENT)
136 printf(" %13.5e |",(((double)(pp->values[i][i_l1_miss]))/((double)(pp->values[i][i_ops]))));
137 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l2_miss!=PERFORMANCE_UNMONITORED_EVENT)
138 printf(" %13.5e |",(((double)(pp->values[i][i_l2_miss]))/((double)(pp->values[i][i_ops]))));
139 if (i_ops!=PERFORMANCE_UNMONITORED_EVENT && i_l3_miss!=PERFORMANCE_UNMONITORED_EVENT)
140 printf(" %13.5e |",(((double)(pp->values[i][i_l3_miss]))/((double)(pp->values[i][i_ops]))));
141 } else {
142 printf("not closed!!!");
143 }
144 printf("\n");
145 }
146 }
147 }
148 PAPI_stop(pp->event_set,values);
149 PAPI_cleanup_eventset(pp->event_set);
150 PAPI_destroy_eventset(&(pp->event_set));
151 }
152 #endif
153 }
154
155 /* */
156 /* switches on a monitor */
157 /* */
158 void Performance_startMonitor(Paso_Performance* pp,int monitor) {
159 #ifdef PAPI
160 int i;
161 long_long values[PERFORMANCE_NUM_EVENTS];
162 #pragma omp barrier
163 #pragma omp single
164 {
165 /* Start counting events in the Event Set */
166 PAPI_read(pp->event_set,values);
167 for (i=0;i<pp->num_events;++i) pp->values[monitor][i]-=values[i];
168 /* set cycles */
169 pp->cycles[monitor]-=PAPI_get_real_cyc();
170 pp->set[monitor]=PERFORMANCE_OPENED;
171 }
172 #endif
173 }
174 /* */
175 /* switches off a monitor */
176 /* */
177 void Performance_stopMonitor(Paso_Performance* pp,int monitor) {
178 #ifdef PAPI
179 int i;
180 long_long values[PERFORMANCE_NUM_EVENTS];
181 #pragma omp barrier
182 #pragma omp single
183 {
184 /* Add the counters in the Event Set */
185 PAPI_read(pp->event_set,values);
186 for (i=0;i<pp->num_events;++i) pp->values[monitor][i]+=values[i];
187 /* set cycles */
188 pp->cycles[monitor]+=PAPI_get_real_cyc();
189 pp->set[monitor]=PERFORMANCE_CLOSED;
190 }
191 #endif
192 }
193

  ViewVC Help
Powered by ViewVC 1.1.26