Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Amesos_Time.h
Go to the documentation of this file.
1 #ifndef AMESOS_TIME_H
2 #define AMESOS_TIME_H
3 
4 #if defined(Amesos_SHOW_DEPRECATED_WARNINGS)
5 #ifdef __GNUC__
6 #warning "The Amesos package is deprecated"
7 #endif
8 #endif
9 
10 #include "Epetra_Comm.h"
11 #include "Epetra_Time.h"
12 #include "Teuchos_Array.hpp"
13 #include "Teuchos_RCP.hpp"
15 #include "Teuchos_Assert.hpp"
16 
17 using Teuchos::RCP;
18 using Teuchos::rcp;
19 using Teuchos::Array;
20 
31  std::string timeName_;
33  double timeVal_;
34 
36  Amesos_Time_Data( std::string timeName, double timeVal ) :
37  timeName_(timeName),
38  timeVal_(timeVal)
39  {}
40 
42  virtual ~Amesos_Time_Data()
43  {}
44 
45 };
46 
57 {
58  public:
59 
62  size_(1)
63  {}
64 
66  virtual ~Amesos_Time()
67  {}
68 
70  inline void CreateTimer(const Epetra_Comm& Comm, int size = 1)
71  {
72  size_ = size;
74 
75  for (int i = 0 ; i < size_ ; ++i)
76  time_[i] = rcp(new Epetra_Time(Comm));
77  }
78 
80  inline void ResetTimer(const int timerID = 0)
81  {
82  time_[timerID]->ResetStartTime();
83  }
84 
86  inline int AddTime(const std::string what, int dataID, const int timerID = 0)
87  {
88  // A valid data id is assumed to be > 0, if the id < 0,
89  // then a new entry in the array is created.
90  if (dataID < 0) {
91  data_.push_back( Amesos_Time_Data( what, time_[timerID]->ElapsedTime() ) );
92  return data_.size()-1;
93  }
94 
95  // Check to make sure the data id is valid
97  timerID >= (int)(data_.size()), std::logic_error,
98  "Amesos_Time::AddTime(...): Error, dataID="<<dataID
99  <<" is >= data_.size()="<<data_.size() <<" for dataName=\""<<what<<"\"!"
100  );
101 
102  // The id is valid and the current elapsed time from the indicated timer will be added in.
103  data_[dataID].timeVal_ += time_[timerID]->ElapsedTime();
104  return dataID;
105  }
106 
108  inline double GetTime(const std::string what) const
109  {
110  int dataSize = (int)(data_.size());
111  for (int i=0; i<dataSize; ++i) {
112  if ( data_[i].timeName_ == what ) {
113  return data_[i].timeVal_;
114  }
115  }
116  return 0.0;
117  }
118 
120  inline double GetTime(const int dataID) const
121  {
122  // Return zero if the dataID is not valid
123  if ( dataID < 0 || dataID >= (int)(data_.size()) ) {
124  return 0.0;
125  }
126  return data_[dataID].timeVal_;
127  }
128 
130  inline void GetTiming( Teuchos::ParameterList& list ) const
131  {
132  int dataSize = (int)(data_.size());
133  for (int i=0; i<dataSize; ++i) {
134  list.set( data_[i].timeName_, data_[i].timeVal_ );
135  }
136  }
137 
138 private:
139 
141  int size_;
142 
145 
148 };
149 
150 #endif
double timeVal_
Current timing data.
Definition: Amesos_Time.h:33
double GetTime(const int dataID) const
Gets the cumulative time using the dataID.
Definition: Amesos_Time.h:120
std::string timeName_
Character string identifying this timing data.
Definition: Amesos_Time.h:31
Amesos_Time_Data(std::string timeName, double timeVal)
Constructor.
Definition: Amesos_Time.h:36
Array< Amesos_Time_Data > data_
Fast accessable container for timing data.
Definition: Amesos_Time.h:147
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Amesos_Time_Data: Simple struct for storing associated data for Amesos_Time.
Definition: Amesos_Time.h:29
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void CreateTimer(const Epetra_Comm &Comm, int size=1)
Initializes the Time object.
Definition: Amesos_Time.h:70
virtual ~Amesos_Time()
Default destructor.
Definition: Amesos_Time.h:66
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void GetTiming(Teuchos::ParameterList &list) const
Load up the current timing information into the parameter list.
Definition: Amesos_Time.h:130
int size_
Number of Epetra_Time objects allocated in this object.
Definition: Amesos_Time.h:141
void resize(size_type new_size, const value_type &x=value_type())
Amesos_Time: Container for timing information.
Definition: Amesos_Time.h:56
int AddTime(const std::string what, int dataID, const int timerID=0)
Adds to field what the time elapsed since last call to ResetTimer().
Definition: Amesos_Time.h:86
void push_back(const value_type &x)
Amesos_Time()
Default constructor to create size timers.
Definition: Amesos_Time.h:61
virtual ~Amesos_Time_Data()
Destructor.
Definition: Amesos_Time.h:42
Array< RCP< Epetra_Time > > time_
Time object.
Definition: Amesos_Time.h:144
size_type size() const
void ResetTimer(const int timerID=0)
Resets the internally stored time object.
Definition: Amesos_Time.h:80
double GetTime(const std::string what) const
Gets the cumulative time using the string.
Definition: Amesos_Time.h:108