/[escript]/branches/doubleplusgood/paso/src/performance.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/paso/src/performance.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26