50 void func_time_monitor1()
56 void func_time_monitor2()
79 return fib (n-1) + fib (n-2);
87 slowLoop (
const size_t n)
89 const double inc = 1 /
static_cast<double> (
n);
92 for (
size_t i = 0; i <
n; ++i) {
93 for (
size_t j = 0; j <
n; ++j) {
94 for (
size_t k = 0; k <
n; ++k) {
113 using Teuchos::parameterList;
116 func_time_monitor1 ();
119 std::ostringstream oss;
125 out << oss.str () << std::endl;
128 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
133 std::ostringstream oss;
136 reportParams->
set (
"Report format",
"YAML");
137 reportParams->
set (
"YAML style",
"compact");
143 out << oss.str () << std::endl;
146 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
151 std::ostringstream oss;
154 reportParams->
set (
"Report format",
"YAML");
155 reportParams->
set (
"YAML style",
"spacious");
161 out << oss.str () << std::endl;
164 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
180 using Teuchos::parameterList;
182 using Teuchos::rcpFromRef;
188 out <<
"Testing TimeMonitor's disableTimer() and enableTimer() methods"
190 OSTab (rcpFromRef (out));
192 out <<
"Creating timers" << endl;
193 const int numTrials = 5;
194 const int numTimers = 3;
196 for (size_type i = 0; i < numTimers; ++i) {
197 std::ostringstream os;
202 out <<
"Running all timers without disabling any" << endl;
207 const size_t loopLength = 25;
208 for (
int k = 0; k < numTrials; ++k) {
209 for (size_type i = 0; i < numTimers; ++i) {
211 slowLoop (loopLength);
214 for (size_type i = 0; i < numTimers; ++i) {
218 out <<
"Disabling one timer and trying again" << endl;
221 for (
int k = 0; k < numTrials; ++k) {
222 for (size_type i = 0; i < numTimers; ++i) {
224 slowLoop (loopLength);
228 for (size_type i = 1; i < numTimers; ++i) {
232 out <<
"Reenabling the timer and trying again" << endl;
235 for (
int k = 0; k < numTrials; ++k) {
236 for (size_type i = 0; i < numTimers; ++i) {
238 slowLoop (loopLength);
242 for (size_type i = 1; i < numTimers; ++i) {
246 out <<
"Test that summarize() reports enabled and disabled timers" << endl;
252 std::ostringstream oss;
258 out << oss.str () << std::endl;
261 for (size_type i = 0; i < numTimers; ++i) {
262 const std::string name = timers[i]->name ();
263 const size_t substr_i = oss.str ().find (name);
280 using Teuchos::parameterList;
290 inputLabels.
push_back (
"NoQuotingNeeded");
291 inputLabels.
push_back (
"No quoting needed");
292 inputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
293 inputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
294 inputLabels.
push_back (
"\"Already quoted: quoting needed\"");
295 inputLabels.
push_back (
"NotQuoted:QuotingNeeded");
296 inputLabels.
push_back (
"Not quoted: quoting needed");
298 inputLabels.
push_back (
"Not quoted \" quoting needed");
299 inputLabels.
push_back (
"Not quoted \" \" quoting needed");
300 inputLabels.
push_back (
"\"Already quoted \" quoting needed\"");
301 inputLabels.
push_back (
"\"Already quoted \" \" quoting needed\"");
305 inputLabels.
push_back (
"Not quoted \\ quoting needed");
306 inputLabels.
push_back (
"Not quoted \\\\ quoting needed");
307 inputLabels.
push_back (
"Not quoted \\ \\ quoting needed");
308 inputLabels.
push_back (
"\"Already quoted \\ quoting needed\"");
309 inputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
310 inputLabels.
push_back (
"\"Already quoted \\ \\ quoting needed\"");
312 outputLabels.
push_back (
"NoQuotingNeeded");
313 outputLabels.
push_back (
"No quoting needed");
314 outputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
315 outputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
316 outputLabels.
push_back (
"\"Already quoted: quoting needed\"");
317 outputLabels.
push_back (
"\"NotQuoted:QuotingNeeded\"");
318 outputLabels.
push_back (
"\"Not quoted: quoting needed\"");
319 outputLabels.
push_back (
"\"Not quoted \\\" quoting needed\"");
320 outputLabels.
push_back (
"\"Not quoted \\\" \\\" quoting needed\"");
321 outputLabels.
push_back (
"\"Already quoted \\\" quoting needed\"");
322 outputLabels.
push_back (
"\"Already quoted \\\" \\\" quoting needed\"");
323 outputLabels.
push_back (
"\"Not quoted \\\\ quoting needed\"");
324 outputLabels.
push_back (
"\"Not quoted \\\\\\\\ quoting needed\"");
325 outputLabels.
push_back (
"\"Not quoted \\\\ \\\\ quoting needed\"");
326 outputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
327 outputLabels.
push_back (
"\"Already quoted \\\\\\\\ quoting needed\"");
328 outputLabels.
push_back (
"\"Already quoted \\\\ \\\\ quoting needed\"");
332 inputLabels.
size () != outputLabels.
size (),
334 "The number of input labels is different than the number of output labels."
335 " Please ask a Teuchos developer to make sure that every test input "
336 "label has a corresponding output label.");
339 for (size_type i = 0; i < inputLabels.
size (); ++i) {
347 const size_t loopLength = 25;
348 for (
int k = 0; k < 3; ++k) {
349 for (size_type i = 0; i < timers.size (); ++i) {
351 slowLoop (loopLength);
356 std::ostringstream oss;
359 reportParams->
set (
"Report format",
"YAML");
360 reportParams->
set (
"YAML style",
"compact");
366 out << oss.str () << std::endl;
369 for (size_type i = 0; i < inputLabels.
size(); ++i) {
370 const size_t pos = oss.str ().find (outputLabels[i]);
376 std::ostringstream oss;
379 reportParams->
set (
"Report format",
"YAML");
380 reportParams->
set (
"YAML style",
"spacious");
386 out << oss.str () << std::endl;
389 for (size_type i = 0; i < inputLabels.
size(); ++i) {
390 const size_t pos = oss.str ().find (outputLabels[i]);
407 using Teuchos::parameterList;
428 labels.
push_back (
"You should not see this");
444 otherLabels.
push_back (
"This is not a pipe");
445 otherLabels.
push_back (
"You should not see this");
448 for (size_type i = 0; i < labels.
size (); ++i) {
456 const size_t loopLength = 25;
457 for (
int k = 0; k < 3; ++k) {
458 for (size_type i = 0; i < timers.
size (); ++i) {
460 slowLoop (loopLength);
469 for (size_type i = 0; i < filters.
size (); ++i) {
471 std::ostringstream oss;
479 out << oss.str () << std::endl;
483 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
484 const size_t pos = oss.str ().find (outLabels[i][j]);
493 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
495 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
496 const size_t pos = oss.str ().find (outLabels[ii][j]);
503 for (size_type j = 0; j < otherLabels.
size(); ++j) {
504 const size_t pos = oss.str ().find (otherLabels[j]);
510 std::ostringstream oss;
513 reportParams->
set (
"Report format",
"YAML");
514 reportParams->
set (
"YAML style",
"compact");
520 out << oss.str () << std::endl;
524 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
525 const size_t pos = oss.str ().find (outLabels[i][j]);
534 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
536 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
537 const size_t pos = oss.str ().find (outLabels[ii][j]);
544 for (size_type j = 0; j < otherLabels.
size(); ++j) {
545 const size_t pos = oss.str ().find (otherLabels[j]);
551 std::ostringstream oss;
554 reportParams->
set (
"Report format",
"YAML");
555 reportParams->
set (
"YAML style",
"spacious");
561 out << oss.str () << std::endl;
565 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
566 const size_t pos = oss.str ().find (outLabels[i][j]);
575 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
577 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
578 const size_t pos = oss.str ().find (outLabels[ii][j]);
585 for (size_type j = 0; j < otherLabels.
size(); ++j) {
586 const size_t pos = oss.str ().find (otherLabels[j]);
615 using Teuchos::parameterList;
618 func_time_monitor2 ();
621 std::ostringstream oss;
627 out << oss.str() << std::endl;
629 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
631 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
636 std::ostringstream oss;
639 reportParams->
set (
"Report format",
"YAML");
640 reportParams->
set (
"YAML style",
"compact");
646 out << oss.str () << std::endl;
648 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
650 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
655 std::ostringstream oss;
658 reportParams->
set (
"Report format",
"YAML");
659 reportParams->
set (
"YAML style",
"spacious");
665 out << oss.str () << std::endl;
667 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
669 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
687 const int numProcs = comm->getSize ();
688 const int myRank = comm->getRank ();
695 int mpiHasBeenInitialized = 0;
696 MPI_Initialized (&mpiHasBeenInitialized);
697 if (! mpiHasBeenInitialized) {
704 std::ostringstream oss;
721 const size_t timerA_loopLength = 150;
722 const size_t timerB_loopLength = 200;
725 for (
size_t k = 0; k < 3; ++k) {
727 slowLoop (timerA_loopLength);
731 slowLoop (timerB_loopLength);
734 const bool alwaysWriteLocal =
false;
735 const bool writeGlobalStats =
true;
736 const bool writeZeroTimers =
true;
743 out << std::endl <<
"Testing intersection of timers:" << std::endl
744 << oss.str() << std::endl;
748 size_t substr_i = oss.str().find (
"Timer A");
751 substr_i = oss.str().find (
"Timer B");
756 std::ostringstream ossUnion;
758 writeZeroTimers,
Union);
763 out << std::endl <<
"Testing union of timers:" << std::endl
764 << ossUnion.str() << std::endl;
768 substr_i = ossUnion.str().find (
"Timer A");
770 substr_i = ossUnion.str().find (
"Timer B");
784 std::ostringstream oss;
798 const size_t timerA_loopLength = 200;
799 const size_t timerB_loopLength = 250;
802 for (
size_t k = 0; k < 3; ++k) {
804 slowLoop (
size_t (timerA_loopLength));
809 slowLoop (
size_t (timerB_loopLength));
812 const bool alwaysWriteLocal =
false;
813 const bool writeGlobalStats =
true;
814 const bool writeZeroTimers =
false;
821 out << oss.str() << std::endl;
824 size_t substr_i = oss.str().find (
"Timer A");
826 substr_i = oss.str().find (
"Timer B");
830 substr_i = oss.str().find (
"Timer C");
845 const int myRank = comm->getRank ();
852 int mpiHasBeenInitialized = 0;
853 MPI_Initialized (&mpiHasBeenInitialized);
854 if (! mpiHasBeenInitialized) {
861 std::ostringstream oss;
879 const size_t timerA_loopLength = 200;
880 const size_t timerB_loopLength = 500;
884 for (
int k = 0; k < 3; ++k) {
886 slowLoop (
size_t (timerA_loopLength));
893 slowLoop (
size_t (timerB_loopLength));
896 const bool alwaysWriteLocal =
false;
897 const bool writeGlobalStats =
true;
898 const bool writeZeroTimers =
false;
900 writeZeroTimers,
Union);
905 out << oss.str() << std::endl;
908 size_t substr_i = oss.str().find (
"Timer A");
910 substr_i = oss.str().find (
"Timer B");
914 substr_i = oss.str().find (
"Timer C");
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
Defines a timer for a specific function.
#define TEST_INEQUALITY(v1, v2)
Assert the inequality of v1 and v2.
static Teuchos::RCP< const Comm< OrdinalType > > getDefaultSerialComm(const Teuchos::RCP< const Comm< OrdinalType > > &comm)
Return a serial comm if the input comm is null.
#define TEST_NOTHROW(code)
Asserr that the statement 'code' does not thrown any excpetions.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
static void disableTimer(const std::string &name)
Disable the timer with the given name.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
static RCP< const ParameterList > getValidReportParameters()
Default parameters (with validators) for report().
basic_OSTab< char > OSTab
static RCP< Time > getNewTimer(const std::string &name)
Return a new timer with the given name (class method).
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="")
Print summary statistics for all timers on the given communicator.
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
A list of parameters of arbitrary type.
void push_back(const value_type &x)
Scope protection wrapper for Teuchos::Time, with timer reporting functionality.
Smart reference counting pointer class for automatic garbage collection.
static void enableTimer(const std::string &name)
Enable the timer with the given name.
A scope-safe timer wrapper class, that can compute global timer statistics.
static void report(Ptr< const Comm< int > > comm, std::ostream &out, const std::string &filter, const RCP< ParameterList > ¶ms=null)
Report timer statistics to the given output stream.
#define TEUCHOS_FUNC_TIME_MONITOR_DIFF(FUNCNAME, DIFF)
Defines a timer for a specific function (with differentiator).
Memory-safe templated array class that encapsulates std::vector.