ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/libmdtools/mdProfile.cpp
Revision: 1334
Committed: Fri Jul 16 18:58:03 2004 UTC (19 years, 11 months ago) by gezelter
File size: 9650 byte(s)
Log Message:
Initial import of OOPSE-1.0 source tree

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