ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/mdProfile.cpp
Revision: 888
Committed: Fri Dec 19 18:53:43 2003 UTC (20 years, 6 months ago) by mmeineke
File size: 8270 byte(s)
Log Message:
the profiling commands work now. Will start adding PROFILE ifdefs into the code

File Contents

# Content
1 #include <sys/time.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <math.h>
6
7 #ifdef IS_MPI
8 #include <mpi.h>
9
10 #include "mpiSimulation.hpp"
11 #endif //is_mpi
12
13 #include "simError.h"
14 #include "mdProfile.hpp"
15
16 namespace mdProfileSpace {
17
18 class ProfileString{
19 public:
20 char myName[MAX_PROFILE_NAMELENGTH];
21 };
22
23 ProfileString theNames[N_PROFILES];
24
25 struct timeval startTime[N_PROFILES];
26 struct timeval endTime[N_PROFILES];
27
28 double accumTime[N_PROFILES];
29
30 #ifdef IS_MPI
31 double globalTime[N_PROFILES];
32 #endif //is_mpi
33
34 }
35
36
37 using namespace mdProfileSpace;
38
39
40 void initProfile( void ){
41
42 int i;
43
44 for( i=0;i<N_PROFILES;i++ ){
45
46 accumTime[i] = 0.0;
47
48 #ifdef IS_MPI
49 globalTime[i] = 0.0;
50 #endif //is_mpi
51 }
52
53 strncpy( theNames[pro1].myName, "BASS Parse", MAX_PROFILE_NAMELENGTH );
54 strncpy( theNames[pro2].myName, "SimSetup->CreateSim", MAX_PROFILE_NAMELENGTH );
55 strncpy( theNames[pro3].myName, "Integrate the Sim", MAX_PROFILE_NAMELENGTH );
56 strncpy( theNames[pro4].myName, "unamed4", MAX_PROFILE_NAMELENGTH );
57 strncpy( theNames[pro5].myName, "unamed5", MAX_PROFILE_NAMELENGTH );
58 strncpy( theNames[pro6].myName, "unamed6", MAX_PROFILE_NAMELENGTH );
59 strncpy( theNames[pro7].myName, "unamed7", MAX_PROFILE_NAMELENGTH );
60 strncpy( theNames[pro8].myName, "unamed8", MAX_PROFILE_NAMELENGTH );
61 }
62
63
64 void startProfile( proNames theProfile ){
65 struct timezone tz;
66
67 gettimeofday( &startTime[theProfile], &tz );
68 }
69
70 void endProfile( proNames theProfile ){
71 struct timezone tz;
72 double startVal, endVal;
73
74 gettimeofday( &endTime[theProfile], &tz );
75
76 startVal = (double)startTime[theProfile].tv_sec
77 + (double)startTime[theProfile].tv_usec / 1000000.0;
78
79 endVal = (double)endTime[theProfile].tv_sec
80 + (double)endTime[theProfile].tv_usec / 1000000.0;
81
82 accumTime[theProfile] += endVal - startVal;
83 }
84
85
86 void writeProfiles( void ){
87
88 int i;
89 double totalTime;
90 double percentTime[N_PROFILES];
91 int days, hours, minutes, secs, msecs;
92 double donkey;
93
94 #ifdef IS_MPI
95 int j;
96
97 MPI_Status istatus;
98
99 double nodeTime;
100 double nodeAccum[N_PROFILES];
101 double nodePercent[N_PROFILES];
102
103 double globalTime;
104 double globalAccum[N_PROFILES];
105 double globalPercent[N_PROFILES];
106 #endif // is_mpi
107
108
109 #ifndef IS_MPI // single processor version
110
111 totalTime = 0.0;
112 for(i=0;i<N_PROFILES;i++)
113 totalTime += accumTime[i];
114
115 for(i=0;i<N_PROFILES;i++)
116 percentTime[i] = accumTime[i] / totalTime;
117
118 fprintf(stdout,
119 " Time Spent Percent Time Name\n"
120 "-------------- ---------------- -----------------------------------------\n"
121 );
122
123 for(i=0;i<N_PROFILES;i++){
124 fprintf(stdout,
125 " %12G %14G %40s\n",
126 accumTime[i],
127 percentTime[i],
128 theNames[i].myName );
129 }
130
131 days = (int)floor( totalTime / 86400 );
132 donkey = totalTime - 86400 * days;
133
134 hours = (int)floor( donkey / 3600 );
135 donkey -= hours * 3600;
136
137 minutes = (int)floor( donkey / 60 );
138 donkey -= minutes * 60;
139
140 secs = (int)donkey;
141 msecs = (int)( (donkey - secs) * 1000 );
142
143 fprintf( stdout,
144 "----------------------------------------------------------------------------\n"
145 " Total Time = %03d:%02d:%02d:%02d.%03d ( %G sec )\n",
146 days,
147 hours,
148 minutes,
149 secs,
150 msecs,
151 totalTime );
152
153 #else // the parrallel version
154
155 if( worldRank == 0 ){
156
157 double *nodeTots = new double[mpiSim->getNumberProcessors()];
158 double *nodePercentTots = new double[mpiSim->getNumberProcessors()];
159
160 totalTime = 0.0;
161 for(i=0;i<N_PROFILES;i++)
162 totalTime += accumTime[i];
163
164 for(i=0;i<N_PROFILES;i++)
165 percentTime[i] = accumTime[i] / totalTime;
166
167 fprintf(stdout,
168 "\n"
169 "----------------------------------------------------------------------------\n"
170 " Output from Node %d: \n"
171 "\n"
172 " Time Spent Percent Time Name\n"
173 "-------------- ---------------- -----------------------------------------\n",
174 worldRank);
175
176 for(i=0;i<N_PROFILES;i++){
177 fprintf(stdout,
178 " %12G %14G %40s\n",
179 accumTime[i],
180 percentTime[i],
181 theNames[i].myName );
182 }
183
184 days = (int)floor( totalTime / 86400 );
185 donkey = totalTime - 86400 * days;
186
187 hours = (int)floor( donkey / 3600 );
188 donkey -= hours * 3600;
189
190 minutes = (int)floor( donkey / 60 );
191 donkey -= minutes * 60;
192
193 secs = (int)donkey;
194 msecs = (int)( (donkey - secs) * 1000 );
195
196 fprintf( stdout,
197 "----------------------------------------------------------------------------\n"
198 " Total Time = %03d:%02d:%02d:%02d.%03d ( %G sec )\n",
199 days,
200 hours,
201 minutes,
202 secs,
203 msecs,
204 totalTime );
205
206 // now the rest of the nodes
207
208 nodeTots[0] = totalTime;
209
210 globalTime = totalTime;
211 for(i=0;i<N_PROFILES;i++)
212 globalAccum[i] = accumTime[i];
213
214
215 for(j=1;j<mpiSim->getNumberProcessors();j++){
216
217 nodeTime = 0.0;
218
219 MPI_Recv(nodeAccum, N_PROFILES, MPI_DOUBLE, j,
220 1, MPI_COMM_WORLD, &istatus );
221
222 for(i=0;i<N_PROFILES;i++){
223 nodeTime += nodeAccum[i];
224 }
225
226 for(i=0;i<N_PROFILES;i++)
227 nodePercent[i] = nodeAccum[i] / nodeTime;
228
229 fprintf(stdout,
230 "\n"
231 "----------------------------------------------------------------------------\n"
232 " Output from Node %d: \n"
233 "\n"
234 " Time Spent Percent Time Name\n"
235 "-------------- ---------------- -----------------------------------------\n",
236 j);
237
238 for(i=0;i<N_PROFILES;i++){
239 fprintf(stdout,
240 " %12G %14G %40s\n",
241 nodeAccum[i],
242 nodePercent[i],
243 theNames[i].myName );
244 }
245
246 days = (int)floor( nodeTime / 86400 );
247 donkey = nodeTime - 86400 * days;
248
249 hours = (int)floor( donkey / 3600 );
250 donkey -= hours * 3600;
251
252 minutes = (int)floor( donkey / 60 );
253 donkey -= minutes * 60;
254
255 secs = (int)donkey;
256 msecs = (int)( (donkey - secs) * 1000 );
257
258 fprintf( stdout,
259 "----------------------------------------------------------------------------\n"
260 " Total Time = %03d:%02d:%02d:%02d.%03d ( %G sec )\n",
261 days,
262 hours,
263 minutes,
264 secs,
265 msecs,
266 nodeTime );
267
268 for(i=0;i<N_PROFILES;i++)
269 globalAccum[i] += nodeAccum[i];
270
271 globalTime += nodeTime;
272 nodeTots[j] = nodeTime;
273 }
274
275 // print out the totals
276
277 for(j=0;j<mpiSim->getNumberProcessors();j++)
278 nodePercentTots[j] = nodeTots[j] / globalTime;
279
280 for(i=0;i<N_PROFILES;i++)
281 globalPercent[i] = globalAccum[i] / globalTime;
282
283 fprintf(stdout,
284 "\n"
285 "----------------------------------------------------------------------------\n"
286 " Total Across Nodes\n"
287 "\n"
288 " Time Spent Percent Time Name\n"
289 "-------------- ---------------- -----------------------------------------\n",
290 j);
291
292 for(i=0;i<N_PROFILES;i++){
293 fprintf(stdout,
294 " %12G %14G %40s\n",
295 globalAccum[i],
296 globalPercent[i],
297 theNames[i].myName );
298 }
299 fprintf(stdout,
300 "\n"
301 "\n" );
302
303 for(j=0;j<mpiSim->getNumberProcessors();j++){
304
305 fprintf(stdout,
306 " %12G %14G node %d\n",
307 nodeTots[j],
308 nodePercentTots[j],
309 j );
310 }
311
312 days = (int)floor( globalTime / 86400 );
313 donkey = nodeTime - 86400 * days;
314
315
316 hours = (int)floor( donkey / 3600 );
317 donkey -= hours * 3600;
318
319 minutes = (int)floor( donkey / 60 );
320 donkey -= minutes * 60;
321
322 secs = (int)donkey;
323 msecs = (int)( (donkey - secs) * 1000 );
324
325 fprintf( stdout,
326 "----------------------------------------------------------------------------\n"
327 " Total Time = %03d:%02d:%02d:%02d.%03d ( %G sec )\n",
328 days,
329 hours,
330 minutes,
331 secs,
332 msecs,
333 globalTime );
334 }
335
336 else{
337
338 for(j=1;j<mpiSim->getNumberProcessors();j++){
339
340 if( worldRank == j ){
341
342 MPI_Send( accumTime, N_PROFILES, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD );
343 }
344 }
345 }
346
347 #endif // is_mpi
348
349
350 }