18 #if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE) 
   19 #include "Kokkos_Core.hpp" 
   73   const int myRank = Teuchos::rank(*comm);
 
   76   timer.
start(
"Total Time");
 
   78     for (
int i=0; i < 10; ++i) {
 
   80       timer.
start(
"Assembly");
 
   81       std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
   82       timer.
stop(
"Assembly");
 
   87         std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
   92           const std::string label = 
"Rank 0 ONLY";
 
   94           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
   99           timer.
start(
"Not Rank 0");
 
  100           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
  102           timer.
stop(
"Not Rank 0");
 
  110   timer.
stop(
"Total Time");
 
  135   std::stringstream sout1;
 
  136   timer.
report(sout1, comm, options);
 
  140   std::stringstream sout2;
 
  141   timer.
report(sout2, comm, options);
 
  145   std::vector<std::tuple<std::string,double,unsigned long>> lineChecks;
 
  146   lineChecks.push_back(std::make_tuple(
"My New Timer:",2.0,1));
 
  147   lineChecks.push_back(std::make_tuple(
"Total Time:",2.0,1));
 
  148   lineChecks.push_back(std::make_tuple(
"Assembly:",1.0,10));
 
  149   lineChecks.push_back(std::make_tuple(
"Solve:",1.0,10));
 
  150   lineChecks.push_back(std::make_tuple(
"Prec:",0.5,10));
 
  159 #if !defined(__GNUC__) \ 
  160     || ( defined(__GNUC__) && (__GNUC__ > 4) ) \ 
  161     || ( defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC__MINOR__ > 8) ) 
  164     const double timerTolerance = 0.25; 
 
  165     std::istringstream is(sout1.str());
 
  166     for (
const auto& check : lineChecks) {
 
  169       std::getline(is,line);
 
  170       std::smatch regexSMatch;
 
  171       std::regex timerName(std::get<0>(check));
 
  172       std::regex_search(line,regexSMatch,timerName);
 
  176       std::regex delimiter(
":\\s|\\s\\[|\\]\\s");
 
  177       std::sregex_token_iterator tok(line.begin(), line.end(),delimiter,-1);
 
  179       const std::string timeAsString = (++tok)->str();
 
  180       const double time = std::stod(timeAsString);
 
  183       const std::string countAsString = (++tok)->str();
 
  184       const unsigned long count = std::stoul(countAsString);
 
  191   out << 
"\n### Printing default report ###" << std::endl;
 
  193   timer.
report(out, comm, defaultOptions);
 
  196   out << 
"\n### Printing aligned_column with timers names on left ###" << std::endl;
 
  203   timer.
report(out, comm, options);
 
  207   out << 
"\n### Printing aligned_column with timers names on right ###" << std::endl;
 
  209   timer.
report(out, comm, options);
 
  215   const int myRank = Teuchos::rank(*comm);
 
  219   timer->startBaseTimer();
 
  220   for (
int i=0; i < 10; ++i) {
 
  221     timer-> start(
"Subtask");
 
  222     timer->incrementUpdates();
 
  223     timer->incrementUpdates(2);
 
  224     timer-> stop(
"Subtask");
 
  226   timer->stopBaseTimer();
 
  231   auto sub_timer = 
const_cast<Teuchos::BaseTimer*
>(timer->findBaseTimer(
"Total Time@Subtask"));
 
  236   TEST_THROW(timer->findBaseTimer(
"Testing misspelled timer name!"),std::runtime_error);
 
  250   top_timer->setAccumulatedTime(5000.0);
 
  251   top_timer->overrideNumCallsForUnitTesting(2);
 
  252   top_timer->overrideNumUpdatesForUnitTesting(3);
 
  253   sub_timer->setAccumulatedTime(4000.0);
 
  254   sub_timer->overrideNumCallsForUnitTesting(4);
 
  255   sub_timer->overrideNumUpdatesForUnitTesting(5);
 
  257     const double timerTolerance = 100.0 * std::numeric_limits<double>::epsilon();
 
  284   TEST_ASSERT(timeMonitorDefaultStackedTimer != timer);
 
  288   timer->start(
"Total Time");
 
  290     for (
int i=0; i < 10; ++i) {
 
  292       timer->start(
"Assembly");
 
  296           std::this_thread::sleep_for(std::chrono::milliseconds{25});
 
  300           std::this_thread::sleep_for(std::chrono::milliseconds{75});
 
  303         std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
  305       timer->stop(
"Assembly");
 
  306       timer->start(
"Solve");
 
  310           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
  314           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
  317         std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
  319       timer->stop(
"Solve");
 
  320       std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
  323   timer->stop(
"Total Time");
 
  324   timer->stopBaseTimer();
 
  326   assert(
size(*comm)>0);
 
  328   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time")).count, 1);
 
  329   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time@Assembly")).count, 10);
 
  332 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER 
  333   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time@Solve@Prec")).count, 10);
 
  334   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time@Solve@GMRES")).count, 10);
 
  338   out << 
"\n### Printing default report ###" << std::endl;
 
  342   timer->report(out, comm, options);
 
  344   out << 
"\n### Printing aligned_column with timers names on left ###" << std::endl;
 
  346   timer->report(out, comm, options);
 
  348   out << 
"\n### Printing aligned_column with timers names on right ###" << std::endl;
 
  355   timer->report(out, comm, options);
 
  358   out << 
"\n### Printing with max_levels=2 ###" << std::endl;
 
  362   timer->report(out, comm, options);
 
  382   timer.
start(
"Outer");
 
  383   timer.
start(
"Inner");
 
  392 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER 
  410 int main( 
int argc, 
char* argv[] )
 
  415 #if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE) 
  416   Kokkos::initialize(argc,argv);
 
  425 #if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE) 
  426   if (Kokkos::is_initialized())
 
  427     Kokkos::finalize_all();
 
#define TEST_ASSERT(v1)
Assert the given statement is true. 
 
void stop(const std::string &name, const bool pop_kokkos_profiling_region=true)
 
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2. 
 
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails)...
 
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test. 
 
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator. 
 
Initialize, finalize, and query the global MPI session. 
 
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL. 
 
static RCP< Time > getNewTimer(const std::string &name)
Return a new timer with the given name (class method). 
 
static int runUnitTestsFromMain(int argc, char *argv[])
Run the unit tests from main() passing in (argc, argv). 
 
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated. 
 
void start(const std::string name, const bool push_kokkos_profiling_region=true)
 
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
 
the basic timer used elsewhere, uses MPI_Wtime for time 
 
static void setStackedTimer(const Teuchos::RCP< Teuchos::StackedTimer > &t)
Sets the StackedTimer that the TimeMonitor will use to insert timings into. 
 
bool print_names_before_values
 
static void setGloballyReduceTestResult(const bool globallyReduceUnitTestResult)
Set if the unit tests should reduce pass/fail across processes. 
 
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Set the stream to print only on the (MPI) process with the given rank. 
 
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator. 
 
void unsortedMergePair(const Array< std::string > &localNames, Array< std::string > &globalNames, const ECounterSetOp setOp)
 
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Assert the relative floating-point equality of rel_error(v1,v2) <= tol. 
 
int main(int argc, char *argv[])
 
void push_back(const value_type &x)
 
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
 
static const Teuchos::RCP< Teuchos::StackedTimer > & getStackedTimer()
Returns the StackedTimer used by the TimeMonitor. 
 
void report(std::ostream &os)
 
Scope protection wrapper for Teuchos::Time, with timer reporting functionality. 
 
Smart reference counting pointer class for automatic garbage collection. 
 
BaseTimer::TimeInfo findTimer(const std::string &name)
 
This class allows one to push and pop timers on and off a stack. 
 
bool output_total_updates
 
Struct for controlling output options like histograms. 
 
A scope-safe timer wrapper class, that can compute global timer statistics. 
 
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.