ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/mdProfile.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/mdProfile.cpp (file contents):
Revision 884 by mmeineke, Thu Dec 18 21:47:51 2003 UTC vs.
Revision 887 by mmeineke, Fri Dec 19 17:25:00 2003 UTC

# Line 1 | Line 1
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  
# Line 62 | Line 74 | void endProfile( proNames theProfile ){
74    gettimeofday( &endTime[theProfile], &tz );
75  
76    startVal = (double)startTime[theProfile].tv_sec
77 <    + (double)startTime[theProfile].tv_usec / 1000.0;
77 >    + (double)startTime[theProfile].tv_usec / 1000000.0;
78  
79    endVal = (double)endTime[theProfile].tv_sec
80 <    + (double)endTime[theProfile].tv_usec / 1000.0;
80 >    + (double)endTime[theProfile].tv_usec / 1000000.0;
81    
82    accumTime[theProfile] += endVal - startVal;
83   }
# Line 74 | Line 86 | void writeProfiles( void ){
86   void writeProfiles( void ){
87  
88    int i;
89 <  double totTime;
89 >  double totalTime;
90    double percentTime[N_PROFILES];
91 <  int days, hours, minutes, secs, usecs;
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 <  totTime = 0.0;
111 >  totalTime = 0.0;
112    for(i=0;i<N_PROFILES;i++)
113 <    totTime += accumTime[i];
113 >    totalTime += accumTime[i];
114  
115    for(i=0;i<N_PROFILES;i++)
116      percentTime[i] = accumTime[i] / totalTime;
# Line 111 | Line 138 | void writeProfiles( void ){
138    donkey -= minutes * 60;
139  
140    secs = (int)donkey;
141 <  usecs = (int)( (donkey - secs) * 1000 );
141 >  msecs = (int)( (donkey - secs) * 1000 );
142  
143    fprintf( stdout,
144             "----------------------------------------------------------------------------\n"
# Line 120 | Line 147 | void writeProfiles( void ){
147             hours,
148             minutes,
149             secs,
150 <           usecs,
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 = 0.0;
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  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines