10 #ifndef TEUCHOS_PERFORMANCEMONITORBASE_H
11 #define TEUCHOS_PERFORMANCEMONITORBASE_H
19 #include "Teuchos_Comm.hpp"
61 const Array<std::string>& localNames,
62 Array<std::string>& globalNames,
77 Array<std::string>& globalNames,
129 : counter_(counter_in), isRecursiveCall_(counter_.isRunning())
132 counter_.incrementNumCalls ();
170 static void freeTableFormat () {
171 if (format_ !=
nullptr) {
186 static void freeCounters () {
187 if (counters_ !=
nullptr) {
204 if (format_ ==
nullptr) {
210 static_cast<void>( atexit(freeTableFormat) );
213 format_ ==
nullptr, std::logic_error,
"Teuchos::PerformanceMonitorBase::"
214 "format: Should never get here! format_ is nullptr.");
264 if (counters_ ==
nullptr) {
265 counters_ =
new std::map<std::string, RCP<T> > ();
270 static_cast<void>( atexit(freeCounters) );
273 counters_ ==
nullptr, std::logic_error,
"Teuchos::PerformanceMonitorBase::"
274 "counters: Should never get here! counters_ is nullptr.");
284 static std::map<std::string, RCP<T> >* counters_;
290 bool isRecursiveCall_;
295 PerformanceMonitorBase<T>::format_ =
nullptr;
298 std::map<std::string, RCP<T> >*
299 PerformanceMonitorBase<T>::counters_ =
nullptr;
305 typedef std::map<std::string, RCP<T> > map_type;
306 typedef typename map_type::iterator iter_type;
308 map_type& ctrs = counters ();
309 iter_type it = ctrs.find (name);
311 if (it == ctrs.end ()) {
312 newCounter =
rcp (
new T (name));
313 #ifdef HAVE_TEUCHOS_DEBUG
314 const bool wasNotThere = ctrs.insert (std::make_pair (name, newCounter)).second;
316 ! wasNotThere, std::logic_error,
317 "getNewCounter: insert() claims that timer \"" << name <<
"\" was "
318 "already there in the map, even though find() claims that it was not. "
319 "Please report this bug to the Teuchos developers.");
322 ctrs.insert (it, std::make_pair (name, newCounter));
323 #endif // HAVE_TEUCHOS_DEBUG
325 newCounter = it->second;
326 #ifdef HAVE_TEUCHOS_DEBUG
328 it->second.is_null (), std::logic_error,
329 "getNewCounter: Timer \"" << name <<
"\" was already there in the map, "
330 "but looking it up by name resulted in a null timer. "
331 "Please report this bug to the Teuchos developers.");
333 name != it->second->name (), std::logic_error,
334 "getNewCounter: Timer \"" << name <<
"\" was already there in the map, "
335 "but looking it up by name resulted in a timer with a different name \""
336 << it->second->name () <<
"\". Please report this bug to the Teuchos "
338 #endif // HAVE_TEUCHOS_DEBUG
341 #ifdef HAVE_TEUCHOS_DEBUG
343 newCounter.
is_null (), std::logic_error,
344 "getNewCounter: At end of method, when creating timer \"" << name
345 <<
"\", newCounter is null. Please report this bug to the Teuchos "
347 #endif // HAVE_TEUCHOS_DEBUG
355 typedef std::map<std::string, RCP<T> > map_type;
356 typedef typename map_type::iterator iter_type;
358 map_type& ctrs = counters ();
359 iter_type it = ctrs.find (name);
360 if (it == ctrs.end ()) {
371 counters ().erase (name);
378 counters ().clear ();
383 #endif // TEUCHOS_PERFORMANCEMONITORBASE_H
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
void mergeCounterNames(const Comm< int > &comm, const Array< std::string > &localNames, Array< std::string > &globalNames, const ECounterSetOp setOp)
Merge counter names over all processors.
void unsortedMergePair(const Array< std::string > &localNames, Array< std::string > &globalNames, const ECounterSetOp setOp)
Templated array class derived from the STL std::vector.
Smart reference counting pointer class for automatic garbage collection.
ECounterSetOp
Set operation type for mergeCounterNames() to perform.
Reference-counted pointer class and non-member templated function implementations.
bool is_null() const
Returns true if the underlying pointer is null.