18 #if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE) 
   19 #include "Kokkos_Core.hpp" 
   73   const int myRank = Teuchos::rank(*comm);
 
   78   timer.
start(
"Total Time");
 
   80     for (
int i=0; i < 10; ++i) {
 
   82       timer.
start(
"Assembly");
 
   83       std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
   84       timer.
stop(
"Assembly");
 
   89         std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
   94           const std::string label = 
"Rank 0 ONLY";
 
   96           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
  101           timer.
start(
"Not Rank 0");
 
  102           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
  104           timer.
stop(
"Not Rank 0");
 
  112   timer.
stop(
"Total Time");
 
  137   std::stringstream sout1;
 
  138   timer.
report(sout1, comm, options);
 
  142   std::stringstream sout2;
 
  143   timer.
report(sout2, comm, options);
 
  147   std::vector<std::tuple<std::string,double,unsigned long>> lineChecks;
 
  148   lineChecks.push_back(std::make_tuple(
"My New Timer:",2.0,1));
 
  149   lineChecks.push_back(std::make_tuple(
"Total Time:",2.0,1));
 
  150   lineChecks.push_back(std::make_tuple(
"Assembly:",1.0,10));
 
  151   lineChecks.push_back(std::make_tuple(
"Solve:",1.0,10));
 
  152   lineChecks.push_back(std::make_tuple(
"Prec:",0.5,10));
 
  161 #if !defined(__GNUC__) \ 
  162     || ( defined(__GNUC__) && (__GNUC__ > 4) ) \ 
  163     || ( defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC__MINOR__ > 8) ) 
  166     const double timerTolerance = 0.25; 
 
  167     std::istringstream is(sout1.str());
 
  168     for (
const auto& check : lineChecks) {
 
  171       std::getline(is,line);
 
  172       std::smatch regexSMatch;
 
  173       std::regex timerName(std::get<0>(check));
 
  174       std::regex_search(line,regexSMatch,timerName);
 
  178       std::regex delimiter(
":\\s|\\s\\[|\\]\\s");
 
  179       std::sregex_token_iterator tok(line.begin(), line.end(),delimiter,-1);
 
  181       const std::string timeAsString = (++tok)->str();
 
  182       const double time = std::stod(timeAsString);
 
  185       const std::string countAsString = (++tok)->str();
 
  186       const unsigned long count = std::stoul(countAsString);
 
  193   out << 
"\n### Printing default report ###" << std::endl;
 
  195   timer.
report(out, comm, defaultOptions);
 
  198   out << 
"\n### Printing aligned_column with timers names on left ###" << std::endl;
 
  205   timer.
report(out, comm, options);
 
  209   out << 
"\n### Printing aligned_column with timers names on right ###" << std::endl;
 
  217   std::string reportOut;
 
  219     std::ostringstream reportOut1;
 
  220     timer.
report(reportOut1, comm, options);
 
  221     std::ostringstream reportOut2;
 
  222     timer.
report(reportOut2, comm, options);
 
  223     reportOut = reportOut1.str();
 
  226   std::string reportXmlOut;
 
  228     std::ostringstream reportOut1;
 
  229     timer.
reportXML(reportOut1, 
"2020_01_01", 
"2020-01-01T01:02:03", comm);
 
  230     std::ostringstream reportOut2;
 
  231     timer.
reportXML(reportOut2, 
"2020_01_01", 
"2020-01-01T01:02:03", comm);
 
  232     reportXmlOut = reportOut1.str();
 
  235   out << reportOut << 
'\n';
 
  236   out << reportXmlOut << 
'\n';
 
  242   const int myRank = Teuchos::rank(*comm);
 
  246   timer->startBaseTimer();
 
  247   for (
int i=0; i < 10; ++i) {
 
  248     timer-> start(
"Subtask");
 
  249     timer->incrementUpdates();
 
  250     timer->incrementUpdates(2);
 
  251     timer-> stop(
"Subtask");
 
  253   timer->stopBaseTimer();
 
  258   auto sub_timer = 
const_cast<Teuchos::BaseTimer*
>(timer->findBaseTimer(
"Total Time@Subtask"));
 
  263   TEST_THROW(timer->findBaseTimer(
"Testing misspelled timer name!"),std::runtime_error);
 
  277   top_timer->setAccumulatedTime(5000.0);
 
  278   top_timer->overrideNumCallsForUnitTesting(2);
 
  279   top_timer->overrideNumUpdatesForUnitTesting(3);
 
  280   sub_timer->setAccumulatedTime(4000.0);
 
  281   sub_timer->overrideNumCallsForUnitTesting(4);
 
  282   sub_timer->overrideNumUpdatesForUnitTesting(5);
 
  284     const double timerTolerance = 100.0 * std::numeric_limits<double>::epsilon();
 
  311   TEST_ASSERT(timeMonitorDefaultStackedTimer != timer);
 
  315   timer->start(
"Total Time");
 
  317     for (
int i=0; i < 10; ++i) {
 
  319       timer->start(
"Assembly");
 
  323           std::this_thread::sleep_for(std::chrono::milliseconds{25});
 
  327           std::this_thread::sleep_for(std::chrono::milliseconds{75});
 
  330         std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
  332       timer->stop(
"Assembly");
 
  333       timer->start(
"Solve");
 
  337           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
  341           std::this_thread::sleep_for(std::chrono::milliseconds{50});
 
  344         std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
  346       timer->stop(
"Solve");
 
  347       std::this_thread::sleep_for(std::chrono::milliseconds{100});
 
  350   timer->stop(
"Total Time");
 
  351   timer->stopBaseTimer();
 
  353   assert(
size(*comm)>0);
 
  355   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time")).count, 1);
 
  356   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time@Assembly")).count, 10);
 
  359 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER 
  360   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time@Solve@Prec")).count, 10);
 
  361   TEST_EQUALITY((timer->findTimer(
"TM:Interoperability@Total Time@Solve@GMRES")).count, 10);
 
  365   out << 
"\n### Printing default report ###" << std::endl;
 
  369   timer->report(out, comm, options);
 
  371   out << 
"\n### Printing aligned_column with timers names on left ###" << std::endl;
 
  373   timer->report(out, comm, options);
 
  375   out << 
"\n### Printing aligned_column with timers names on right ###" << std::endl;
 
  382   timer->report(out, comm, options);
 
  385   out << 
"\n### Printing with max_levels=2 ###" << std::endl;
 
  389   timer->report(out, comm, options);
 
  419   const int myRank = Teuchos::rank(*comm);
 
  423   out << 
"\n### Printing default report ###" << std::endl;
 
  427   timer.
report(out, comm, options);
 
  429     std::ostringstream os;
 
  430     timer.
report(os, comm, options);
 
  432       TEST_ASSERT(os.str().find(
"L2a") == std::string::npos); 
 
  433       TEST_ASSERT(os.str().find(
"L2b") != std::string::npos); 
 
  434       TEST_ASSERT(os.str().find(
"L1b") == std::string::npos); 
 
  438   out << 
"\n### Printing aligned_column with timers names on left ###" << std::endl;
 
  440   timer.
report(out, comm, options);
 
  442     std::ostringstream os;
 
  443     timer.
report(os, comm, options);
 
  445       TEST_ASSERT(os.str().find(
"L2a") == std::string::npos); 
 
  446       TEST_ASSERT(os.str().find(
"L2b") != std::string::npos); 
 
  447       TEST_ASSERT(os.str().find(
"L1b") == std::string::npos); 
 
  451   out << 
"\n### Printing aligned_column with timers names on right ###" << std::endl;
 
  454   timer.
report(out, comm, options);
 
  456     std::ostringstream os;
 
  457     timer.
report(os, comm, options);
 
  459       TEST_ASSERT(os.str().find(
"L2a") == std::string::npos); 
 
  460       TEST_ASSERT(os.str().find(
"L2b") != std::string::npos); 
 
  461       TEST_ASSERT(os.str().find(
"L1b") == std::string::npos); 
 
  473   if (comm->getSize() < 2)
 
  475   const int myRank = Teuchos::rank(*comm);
 
  479   else if (myRank == 1)
 
  486   out << 
"\n### Printing default report ###" << std::endl;
 
  492   timer.
report(out, comm, options);
 
  494     std::ostringstream os;
 
  495     timer.
report(os, comm, options);
 
  497       TEST_ASSERT(os.str().find(
"proc min=0") != std::string::npos);
 
  498       TEST_ASSERT(os.str().find(
"proc max=1") != std::string::npos);
 
  521   timer.
start(
"Outer");
 
  522   timer.
start(
"Inner");
 
  531 #ifdef HAVE_TEUCHOS_ADD_TIME_MONITOR_TO_STACKED_TIMER 
  549 int main( 
int argc, 
char* argv[] )
 
  554 #if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE) 
  555   Kokkos::initialize(argc,argv);
 
  564 #if defined(HAVE_TEUCHOS_KOKKOS_PROFILING) && defined(HAVE_TEUCHOSCORE_KOKKOSCORE) 
  565   if (Kokkos::is_initialized())
 
  566     Kokkos::finalize_all();
 
  573 #if !defined(__GNUC__) || ( defined(__GNUC__) && (__GNUC__ > 4) ) 
  580   std::ostringstream os;
 
  591   out << os.str() << std::endl;
 
  597   TEST_ASSERT(os.str().find(
"L1") != std::string::npos);
 
  598   TEST_ASSERT(os.str().find(
"L2") != std::string::npos);
 
  599   TEST_ASSERT(os.str().find(
"L3") == std::string::npos);
 
void setVerboseOstream(const Teuchos::RCP< std::ostream > &os)
 
static Teuchos::RCP< Teuchos::StackedTimer > getStackedTimer()
The StackedTimer used by the TimeMonitor. 
 
#define TEST_ASSERT(v1)
Assert the given statement is true. 
 
void stop(const std::string &name, const bool pop_kokkos_profiling_region=true)
 
void enableVerboseTimestamps(const unsigned levels)
 
void enableVerbose(const bool enable_verbose)
 
#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 
 
void reportXML(std::ostream &os, const std::string &datestamp, const std::string ×tamp, Teuchos::RCP< const Teuchos::Comm< int > > comm)
 
static void setStackedTimer(const Teuchos::RCP< Teuchos::StackedTimer > &t)
Sets the StackedTimer into which the TimeMonitor will insert timings. 
 
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. 
 
const BaseTimer * findBaseTimer(const std::string &name) const 
 
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...
 
void report(std::ostream &os)
 
Scope guard for Teuchos::Time, with MPI collective timer reporting. 
 
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
 
Scope guard for Time, that can compute MPI collective timer statistics. 
 
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.