src/Utility/IpplTimings.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
00027 #include "Utility/IpplTimings.h"
00028 #include "Utility/Inform.h"
00029 #include "Utility/IpplInfo.h"
00030 #include "Message/GlobalComm.h"
00031 #include "PETE/IpplExpressions.h"
00032 
00033 #include <fstream>
00034 #include <iostream>
00035 // static data members of IpplTimings class
00036 IpplTimings::TimerList_t IpplTimings::TimerList;
00037 IpplTimings::TimerMap_t  IpplTimings::TimerMap;
00038 
00039 
00041 // default constructor
00042 IpplTimings::IpplTimings() { }
00043 
00044 
00046 // destructor
00047 IpplTimings::~IpplTimings() { }
00048 
00049 
00051 // create a timer, or get one that already exists
00052 IpplTimings::TimerRef IpplTimings::getTimer(const char *nm) {
00053   string s(nm);
00054   TimerInfo *tptr = 0;
00055   TimerMap_t::iterator loc = TimerMap.find(s);
00056   if (loc == TimerMap.end()) {
00057     tptr = new TimerInfo;
00058     tptr->indx = TimerList.size();
00059     tptr->name = s;
00060     TimerMap.insert(TimerMap_t::value_type(s,tptr));
00061     TimerList.push_back(my_auto_ptr<TimerInfo>(tptr));
00062   } else {
00063     tptr = (*loc).second;
00064   }
00065   return tptr->indx;
00066 }
00067 
00068 
00070 // start a timer
00071 void IpplTimings::startTimer(TimerRef t) {
00072   if (t < 0 || t >= TimerList.size())
00073     return;
00074   TimerList[t]->start();
00075 }
00076 
00077 
00079 // stop a timer, and accumulate it's values
00080 void IpplTimings::stopTimer(TimerRef t) {
00081   if (t < 0 || t >= TimerList.size())
00082     return;
00083   TimerList[t]->stop();
00084 }
00085 
00086 
00088 // clear a timer, by turning it off and throwing away its time
00089 void IpplTimings::clearTimer(TimerRef t) {
00090   if (t < 0 || t >= TimerList.size())
00091     return;
00092   TimerList[t]->clear();
00093 }
00094 
00095 #ifdef IPPL_XT3
00096 
00097 // print out the timing results
00098 void IpplTimings::print() {
00099     int i,j;
00100     if (TimerList.size() < 1)
00101         return;
00102     
00103     // report the average time for each timer
00104     Inform msg("Timings");
00105     msg << "-----------------------------------------------------------------";
00106     msg << endl;
00107     msg << "     Timing (dclock) results for " << Ippl::getNodes() << " nodes:" << endl;
00108     msg << "-----------------------------------------------------------------";
00109     msg << endl;
00110     for (i=0; i<1; ++i){
00111         TimerInfo *tptr = TimerList[i].get();
00112         double walltotal = 0.0; 
00113         reduce(tptr->wallTime, walltotal, OpMaxAssign());
00114         msg << tptr->name.c_str() << " ";
00115         for (j=strlen(tptr->name.c_str()); j < 10; ++j)
00116             msg << ".";
00117         msg << " Wall tot = ";
00118         msg.width(10);
00119         msg << walltotal;
00120         msg << endl << endl;
00121     }
00122 
00123     for (i=1; i < TimerList.size(); ++i) {
00124         TimerInfo *tptr = TimerList[i].get();
00125         double wallmax = 0.0, wallmin = 0.0;
00126         double wallavg = 0.0 ;
00127         reduce(tptr->wallTime, wallmax, OpMaxAssign());
00128         reduce(tptr->wallTime, wallmin, OpMinAssign());
00129         reduce(tptr->wallTime, wallavg, OpAddAssign());
00130         msg << tptr->name.c_str() << " ";
00131         for (j=strlen(tptr->name.c_str()); j < 10; ++j)
00132             msg << ".";
00133         msg << " Wall max = ";
00134         msg.width(10);
00135         msg << wallmax << endl;
00136         for (j = 0; j < 21; ++j)
00137             msg << " ";
00138         msg << " Wall avg = ";
00139         msg.width(10);
00140         msg << wallavg / Ippl::getNodes() << endl;
00141         for (j = 0; j < 21; ++j)
00142             msg << " ";
00143         msg << " Wall min = ";
00144         msg.width(10);
00145         msg << wallmin << endl << endl;
00146     }
00147     msg << "-----------------------------------------------------------------";
00148     msg << endl;
00149 }
00150 
00151 #else
00152 
00154 // print out the timing results
00155 void IpplTimings::print() {
00156   int i,j;
00157   if (TimerList.size() < 1)
00158     return;
00159 
00160   // report the average time for each timer
00161   Inform msg("Timings");
00162   msg << "-----------------------------------------------------------------";
00163   msg << endl;
00164   msg << "     Timing results for " << Ippl::getNodes() << " nodes:" << endl;
00165   msg << "-----------------------------------------------------------------";
00166   msg << endl;
00167   for (i=0; i<1; ++i){
00168     TimerInfo *tptr = TimerList[i].get();
00169     double walltotal = 0.0, cputotal = 0.0;
00170     reduce(tptr->wallTime, walltotal, OpMaxAssign());
00171     reduce(tptr->cpuTime, cputotal, OpMaxAssign());
00172     msg << tptr->name.c_str() << " ";
00173     for (j=strlen(tptr->name.c_str()); j < 20; ++j)
00174       msg << ".";
00175     msg << " Wall tot = ";
00176     msg.width(10);
00177     msg << walltotal << ", CPU tot = ";
00178     msg.width(10);
00179     msg << cputotal << endl << endl;
00180   }
00181 
00182   for (i=1; i < TimerList.size(); ++i) {
00183     TimerInfo *tptr = TimerList[i].get();
00184     double wallmax = 0.0, cpumax = 0.0, wallmin = 0.0, cpumin = 0.0;
00185     double wallavg = 0.0, cpuavg = 0.0;
00186     reduce(tptr->wallTime, wallmax, OpMaxAssign());
00187     reduce(tptr->cpuTime,  cpumax,  OpMaxAssign());
00188     reduce(tptr->wallTime, wallmin, OpMinAssign());
00189     reduce(tptr->cpuTime,  cpumin,  OpMinAssign());
00190     reduce(tptr->wallTime, wallavg, OpAddAssign());
00191     reduce(tptr->cpuTime,  cpuavg,  OpAddAssign());
00192     msg << tptr->name.c_str() << " ";
00193     for (j=strlen(tptr->name.c_str()); j < 20; ++j)
00194       msg << ".";
00195     msg << " Wall max = ";
00196     msg.width(10);
00197     msg << wallmax << ", CPU max = ";
00198     msg.width(10);
00199     msg << cpumax << endl;
00200     for (j = 0; j < 21; ++j)
00201       msg << " ";
00202     msg << " Wall avg = ";
00203     msg.width(10);
00204     msg << wallavg / Ippl::getNodes() << ", CPU avg = ";
00205     msg.width(10);
00206     msg << cpuavg / Ippl::getNodes() << endl;
00207     for (j = 0; j < 21; ++j)
00208       msg << " ";
00209     msg << " Wall min = ";
00210     msg.width(10);
00211     msg << wallmin << ", CPU min = ";
00212     msg.width(10);
00213     msg << cpumin << endl << endl;
00214   }
00215   msg << "-----------------------------------------------------------------";
00216   msg << endl;
00217 }
00218 #endif
00219 
00221 // save the timing results into a file
00222 void IpplTimings::print(string fn) {
00223   int i,j;
00224 
00225   ofstream *timer_stream;
00226   Inform *msg;
00227 
00228   if (TimerList.size() < 1)
00229     return;
00230   
00231   timer_stream = new ofstream;
00232   timer_stream->open( fn.c_str(), ios::out );
00233   msg = new Inform( 0, *timer_stream, 0 );
00234 
00235   // report the average time for each timer
00236   // Inform msg("Timings");
00237 
00238   *msg << "-----------------------------------------------------------------";
00239   *msg << endl;
00240   *msg << "     Timing results for " << Ippl::getNodes() << " nodes:" << endl;
00241   *msg << "-----------------------------------------------------------------";
00242   *msg << endl;
00243   for (i=0; i<1; ++i){
00244     TimerInfo *tptr = TimerList[i].get();
00245     double walltotal = 0.0, cputotal = 0.0;
00246     reduce(tptr->wallTime, walltotal, OpMaxAssign());
00247     reduce(tptr->cpuTime, cputotal, OpMaxAssign());
00248     *msg << tptr->name.c_str() << " ";
00249     for (j=strlen(tptr->name.c_str()); j < 20; ++j)
00250       *msg << ".";
00251     *msg << " Wall tot = ";
00252     msg->width(10);
00253     *msg << walltotal << ", CPU tot = ";
00254     msg->width(10);
00255     *msg << cputotal << endl << endl;
00256   }
00257 
00258   for (i=1; i < TimerList.size(); ++i) {
00259     TimerInfo *tptr = TimerList[i].get();
00260     double wallmax = 0.0, cpumax = 0.0, wallmin = 0.0, cpumin = 0.0;
00261     double wallavg = 0.0, cpuavg = 0.0;
00262     reduce(tptr->wallTime, wallmax, OpMaxAssign());
00263     reduce(tptr->cpuTime,  cpumax,  OpMaxAssign());
00264     reduce(tptr->wallTime, wallmin, OpMinAssign());
00265     reduce(tptr->cpuTime,  cpumin,  OpMinAssign());
00266     reduce(tptr->wallTime, wallavg, OpAddAssign());
00267     reduce(tptr->cpuTime,  cpuavg,  OpAddAssign());
00268     *msg << tptr->name.c_str() << " ";
00269     for (j=strlen(tptr->name.c_str()); j < 20; ++j)
00270       *msg << ".";
00271     *msg << " Wall max = ";
00272     msg->width(10);
00273     *msg << wallmax << ", CPU max = ";
00274     msg->width(10);
00275     *msg << cpumax << endl;
00276     for (j = 0; j < 21; ++j)
00277       *msg << " ";
00278     *msg << " Wall avg = ";
00279     msg->width(10);
00280     *msg << wallavg / Ippl::getNodes() << ", CPU avg = ";
00281     msg->width(10);
00282     *msg << cpuavg / Ippl::getNodes() << endl;
00283     for (j = 0; j < 21; ++j)
00284       *msg << " ";
00285     *msg << " Wall min = ";
00286     msg->width(10);
00287     *msg << wallmin << ", CPU min = ";
00288     msg->width(10);
00289     *msg << cpumin << endl << endl;
00290   }
00291   *msg << "-----------------------------------------------------------------";
00292   *msg << endl;
00293 
00294   timer_stream->close();
00295   delete msg;
00296 }
00297 
00298 
00299 /***************************************************************************
00300  * $RCSfile: IpplTimings.cpp,v $   $Author: adelmann $
00301  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00302  ***************************************************************************/
00303 
00304 
00305 /***************************************************************************
00306  * $RCSfile: addheaderfooter,v $   $Author: adelmann $
00307  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:17 $
00308  * IPPL_VERSION_ID: $Id: addheaderfooter,v 1.1.1.1 2003/01/23 07:40:17 adelmann Exp $ 
00309  ***************************************************************************/
00310 

Generated on Mon Jan 16 13:23:59 2006 for IPPL by  doxygen 1.4.6