Amesos Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
Amesos_Time.h
Go to the documentation of this file.
1#ifndef AMESOS_TIME_H
2#define AMESOS_TIME_H
3
4#include "Epetra_Comm.h"
5#include "Epetra_Time.h"
6#include "Teuchos_Array.hpp"
7#include "Teuchos_RCP.hpp"
8#include "Teuchos_ParameterList.hpp"
9#include "Teuchos_Assert.hpp"
10
11using Teuchos::RCP;
12using Teuchos::rcp;
13using Teuchos::Array;
14
25 std::string timeName_;
27 double timeVal_;
28
30 Amesos_Time_Data( std::string timeName, double timeVal ) :
31 timeName_(timeName),
32 timeVal_(timeVal)
33 {}
34
37 {}
38
39};
40
51{
52 public:
53
56 size_(1)
57 {}
58
60 virtual ~Amesos_Time()
61 {}
62
64 inline void CreateTimer(const Epetra_Comm& Comm, int size = 1)
65 {
66 size_ = size;
67 time_.resize(size_);
68
69 for (int i = 0 ; i < size_ ; ++i)
70 time_[i] = rcp(new Epetra_Time(Comm));
71 }
72
74 inline void ResetTimer(const int timerID = 0)
75 {
76 time_[timerID]->ResetStartTime();
77 }
78
80 inline int AddTime(const std::string what, int dataID, const int timerID = 0)
81 {
82 // A valid data id is assumed to be > 0, if the id < 0,
83 // then a new entry in the array is created.
84 if (dataID < 0) {
85 data_.push_back( Amesos_Time_Data( what, time_[timerID]->ElapsedTime() ) );
86 return data_.size()-1;
87 }
88
89 // Check to make sure the data id is valid
90 TEUCHOS_TEST_FOR_EXCEPTION(
91 timerID >= (int)(data_.size()), std::logic_error,
92 "Amesos_Time::AddTime(...): Error, dataID="<<dataID
93 <<" is >= data_.size()="<<data_.size() <<" for dataName=\""<<what<<"\"!"
94 );
95
96 // The id is valid and the current elapsed time from the indicated timer will be added in.
97 data_[dataID].timeVal_ += time_[timerID]->ElapsedTime();
98 return dataID;
99 }
100
102 inline double GetTime(const std::string what) const
103 {
104 int dataSize = (int)(data_.size());
105 for (int i=0; i<dataSize; ++i) {
106 if ( data_[i].timeName_ == what ) {
107 return data_[i].timeVal_;
108 }
109 }
110 return 0.0;
111 }
112
114 inline double GetTime(const int dataID) const
115 {
116 // Return zero if the dataID is not valid
117 if ( dataID < 0 || dataID >= (int)(data_.size()) ) {
118 return 0.0;
119 }
120 return data_[dataID].timeVal_;
121 }
122
124 inline void GetTiming( Teuchos::ParameterList& list ) const
125 {
126 int dataSize = (int)(data_.size());
127 for (int i=0; i<dataSize; ++i) {
128 list.set( data_[i].timeName_, data_[i].timeVal_ );
129 }
130 }
131
132private:
133
135 int size_;
136
138 Array<RCP<Epetra_Time> > time_;
139
141 Array< Amesos_Time_Data > data_;
142};
143
144#endif
Amesos_Time: Container for timing information.
Definition: Amesos_Time.h:51
double GetTime(const std::string what) const
Gets the cumulative time using the string.
Definition: Amesos_Time.h:102
void ResetTimer(const int timerID=0)
Resets the internally stored time object.
Definition: Amesos_Time.h:74
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:80
int size_
Number of Epetra_Time objects allocated in this object.
Definition: Amesos_Time.h:135
double GetTime(const int dataID) const
Gets the cumulative time using the dataID.
Definition: Amesos_Time.h:114
void CreateTimer(const Epetra_Comm &Comm, int size=1)
Initializes the Time object.
Definition: Amesos_Time.h:64
Array< RCP< Epetra_Time > > time_
Time object.
Definition: Amesos_Time.h:138
Amesos_Time()
Default constructor to create size timers.
Definition: Amesos_Time.h:55
virtual ~Amesos_Time()
Default destructor.
Definition: Amesos_Time.h:60
Array< Amesos_Time_Data > data_
Fast accessable container for timing data.
Definition: Amesos_Time.h:141
void GetTiming(Teuchos::ParameterList &list) const
Load up the current timing information into the parameter list.
Definition: Amesos_Time.h:124
Amesos_Time_Data: Simple struct for storing associated data for Amesos_Time.
Definition: Amesos_Time.h:23
Amesos_Time_Data(std::string timeName, double timeVal)
Constructor.
Definition: Amesos_Time.h:30
double timeVal_
Current timing data.
Definition: Amesos_Time.h:27
virtual ~Amesos_Time_Data()
Destructor.
Definition: Amesos_Time.h:36
std::string timeName_
Character string identifying this timing data.
Definition: Amesos_Time.h:25