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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4873 - (show annotations)
Wed Apr 16 06:38:51 2014 UTC (5 years, 5 months ago) by caltinay
File size: 7809 byte(s)
whitespace only changes.

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

Properties

Name Value
svn:mergeinfo /branches/amg_from_3530/paso/src/performance.cpp:3531-3826 /branches/lapack2681/paso/src/performance.cpp:2682-2741 /branches/pasowrap/paso/src/performance.cpp:3661-3674 /branches/py3_attempt2/paso/src/performance.cpp:3871-3891 /branches/restext/paso/src/performance.cpp:2610-2624 /branches/ripleygmg_from_3668/paso/src/performance.cpp:3669-3791 /branches/stage3.0/paso/src/performance.cpp:2569-2590 /branches/symbolic_from_3470/paso/src/performance.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/paso/src/performance.cpp:3517-3974 /release/3.0/paso/src/performance.cpp:2591-2601 /trunk/paso/src/performance.cpp:4257-4344 /trunk/ripley/test/python/paso/src/performance.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26