Amesos Package Browser (Single Doxygen Collection) Development
Amesos_Time.h
Go to the documentation of this file.
00001 #ifndef AMESOS_TIME_H
00002 #define AMESOS_TIME_H
00003 
00004 #include "Epetra_Comm.h"
00005 #include "Epetra_Time.h"
00006 #include "Teuchos_Array.hpp"
00007 #include "Teuchos_RCP.hpp"
00008 #include "Teuchos_ParameterList.hpp"
00009 #include "Teuchos_Assert.hpp"
00010 
00011 using Teuchos::RCP;
00012 using Teuchos::rcp;
00013 using Teuchos::Array;
00014 
00023 struct Amesos_Time_Data {
00025   std::string timeName_;
00027   double timeVal_;
00028   
00030   Amesos_Time_Data( std::string timeName, double timeVal ) : 
00031     timeName_(timeName), 
00032     timeVal_(timeVal)
00033   {}
00034   
00036   virtual ~Amesos_Time_Data() 
00037   {}
00038   
00039 };
00040 
00050 class Amesos_Time
00051 {
00052  public:
00053   
00055   Amesos_Time() :
00056     size_(1)
00057   {}
00058     
00060   virtual ~Amesos_Time()
00061   {}
00062     
00064   inline void CreateTimer(const Epetra_Comm& Comm, int size = 1)
00065   {
00066     size_ = size;
00067     time_.resize(size_);
00068 
00069     for (int i = 0 ; i < size_ ; ++i)
00070       time_[i] = rcp(new Epetra_Time(Comm));
00071   }
00072 
00074   inline void ResetTimer(const int timerID = 0)
00075   {
00076     time_[timerID]->ResetStartTime();
00077   }
00078 
00080   inline int AddTime(const std::string what, int dataID, const int timerID = 0)
00081   {
00082     // A valid data id is assumed to be > 0, if the id < 0, 
00083     // then a new entry in the array is created.
00084     if (dataID < 0) {
00085       data_.push_back( Amesos_Time_Data( what, time_[timerID]->ElapsedTime() ) );
00086       return data_.size()-1;
00087     }
00088     
00089     // Check to make sure the data id is valid
00090     TEUCHOS_TEST_FOR_EXCEPTION(
00091       timerID >=  (int)(data_.size()), std::logic_error,
00092       "Amesos_Time::AddTime(...): Error, dataID="<<dataID
00093       <<" is >= data_.size()="<<data_.size() <<" for dataName=\""<<what<<"\"!"
00094     );
00095    
00096     // The id is valid and the current elapsed time from the indicated timer will be added in. 
00097     data_[dataID].timeVal_ += time_[timerID]->ElapsedTime();
00098     return dataID;
00099   }
00100 
00102   inline double GetTime(const std::string what) const
00103   {
00104     int dataSize = (int)(data_.size());
00105     for (int i=0; i<dataSize; ++i) {
00106       if ( data_[i].timeName_ == what ) {
00107         return data_[i].timeVal_;
00108       }
00109     }
00110     return 0.0;
00111   }
00112 
00114   inline double GetTime(const int dataID) const
00115   {
00116     // Return zero if the dataID is not valid
00117     if ( dataID < 0 || dataID >= (int)(data_.size()) ) {
00118       return 0.0;
00119     }
00120     return data_[dataID].timeVal_;
00121   }
00122   
00124   inline void GetTiming( Teuchos::ParameterList& list ) const
00125   {
00126     int dataSize = (int)(data_.size());
00127     for (int i=0; i<dataSize; ++i) {
00128       list.set( data_[i].timeName_, data_[i].timeVal_ );
00129     }
00130   }
00131 
00132 private:
00133  
00135   int size_;
00136 
00138   Array<RCP<Epetra_Time> > time_;
00139   
00141   Array< Amesos_Time_Data > data_;
00142 };
00143 
00144 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines