60 #pragma comment(lib, "Ws2_32.lib") 61 # include <Winsock2.h> 71 void func_time_monitor1()
77 void func_time_monitor2()
104 return fib (
n-1) + fib (
n-2);
114 slowLoop (
const size_t n)
116 const double inc = 1 /
static_cast<double> (
n);
119 for (
size_t i = 0; i <
n; ++i) {
120 for (
size_t j = 0; j <
n; ++j) {
121 for (
size_t k = 0; k <
n; ++k) {
140 using Teuchos::parameterList;
143 func_time_monitor1 ();
146 std::ostringstream oss;
152 out << oss.str () << std::endl;
155 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
160 std::ostringstream oss;
163 reportParams->
set (
"Report format",
"YAML");
164 reportParams->
set (
"YAML style",
"compact");
170 out << oss.str () << std::endl;
173 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
178 std::ostringstream oss;
181 reportParams->
set (
"Report format",
"YAML");
182 reportParams->
set (
"YAML style",
"spacious");
188 out << oss.str () << std::endl;
191 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
207 using Teuchos::parameterList;
209 using Teuchos::rcpFromRef;
215 out <<
"Testing TimeMonitor's disableTimer() and enableTimer() methods" 217 OSTab (rcpFromRef (out));
219 out <<
"Creating timers" << endl;
220 const int numTrials = 5;
221 const int numTimers = 3;
223 for (size_type i = 0; i < numTimers; ++i) {
224 std::ostringstream os;
229 out <<
"Running all timers without disabling any" << endl;
234 const size_t loopLength = 25;
235 for (
int k = 0; k < numTrials; ++k) {
236 for (size_type i = 0; i < numTimers; ++i) {
238 slowLoop (loopLength);
241 for (size_type i = 0; i < numTimers; ++i) {
245 out <<
"Disabling one timer and trying again" << endl;
248 for (
int k = 0; k < numTrials; ++k) {
249 for (size_type i = 0; i < numTimers; ++i) {
251 slowLoop (loopLength);
255 for (size_type i = 1; i < numTimers; ++i) {
259 out <<
"Reenabling the timer and trying again" << endl;
262 for (
int k = 0; k < numTrials; ++k) {
263 for (size_type i = 0; i < numTimers; ++i) {
265 slowLoop (loopLength);
269 for (size_type i = 1; i < numTimers; ++i) {
273 out <<
"Test that summarize() reports enabled and disabled timers" << endl;
279 std::ostringstream oss;
285 out << oss.str () << std::endl;
288 for (size_type i = 0; i < numTimers; ++i) {
289 const std::string name = timers[i]->name ();
290 const size_t substr_i = oss.str ().find (name);
307 using Teuchos::parameterList;
317 inputLabels.
push_back (
"NoQuotingNeeded");
318 inputLabels.
push_back (
"No quoting needed");
319 inputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
320 inputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
321 inputLabels.
push_back (
"\"Already quoted: quoting needed\"");
322 inputLabels.
push_back (
"NotQuoted:QuotingNeeded");
323 inputLabels.
push_back (
"Not quoted: quoting needed");
325 inputLabels.
push_back (
"Not quoted \" quoting needed");
326 inputLabels.
push_back (
"Not quoted \" \" quoting needed");
327 inputLabels.
push_back (
"\"Already quoted \" quoting needed\"");
328 inputLabels.
push_back (
"\"Already quoted \" \" quoting needed\"");
332 inputLabels.
push_back (
"Not quoted \\ quoting needed");
333 inputLabels.
push_back (
"Not quoted \\\\ quoting needed");
334 inputLabels.
push_back (
"Not quoted \\ \\ quoting needed");
335 inputLabels.
push_back (
"\"Already quoted \\ quoting needed\"");
336 inputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
337 inputLabels.
push_back (
"\"Already quoted \\ \\ quoting needed\"");
339 outputLabels.
push_back (
"NoQuotingNeeded");
340 outputLabels.
push_back (
"No quoting needed");
341 outputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
342 outputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
343 outputLabels.
push_back (
"\"Already quoted: quoting needed\"");
344 outputLabels.
push_back (
"\"NotQuoted:QuotingNeeded\"");
345 outputLabels.
push_back (
"\"Not quoted: quoting needed\"");
346 outputLabels.
push_back (
"\"Not quoted \\\" quoting needed\"");
347 outputLabels.
push_back (
"\"Not quoted \\\" \\\" quoting needed\"");
348 outputLabels.
push_back (
"\"Already quoted \\\" quoting needed\"");
349 outputLabels.
push_back (
"\"Already quoted \\\" \\\" quoting needed\"");
350 outputLabels.
push_back (
"\"Not quoted \\\\ quoting needed\"");
351 outputLabels.
push_back (
"\"Not quoted \\\\\\\\ quoting needed\"");
352 outputLabels.
push_back (
"\"Not quoted \\\\ \\\\ quoting needed\"");
353 outputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
354 outputLabels.
push_back (
"\"Already quoted \\\\\\\\ quoting needed\"");
355 outputLabels.
push_back (
"\"Already quoted \\\\ \\\\ quoting needed\"");
359 inputLabels.
size () != outputLabels.
size (),
361 "The number of input labels is different than the number of output labels." 362 " Please ask a Teuchos developer to make sure that every test input " 363 "label has a corresponding output label.");
366 for (size_type i = 0; i < inputLabels.
size (); ++i) {
374 const size_t loopLength = 25;
375 for (
int k = 0; k < 3; ++k) {
376 for (size_type i = 0; i < timers.size (); ++i) {
378 slowLoop (loopLength);
383 std::ostringstream oss;
386 reportParams->
set (
"Report format",
"YAML");
387 reportParams->
set (
"YAML style",
"compact");
393 out << oss.str () << std::endl;
396 for (size_type i = 0; i < inputLabels.
size(); ++i) {
397 const size_t pos = oss.str ().find (outputLabels[i]);
403 std::ostringstream oss;
406 reportParams->
set (
"Report format",
"YAML");
407 reportParams->
set (
"YAML style",
"spacious");
413 out << oss.str () << std::endl;
416 for (size_type i = 0; i < inputLabels.
size(); ++i) {
417 const size_t pos = oss.str ().find (outputLabels[i]);
434 using Teuchos::parameterList;
455 labels.
push_back (
"You should not see this");
471 otherLabels.
push_back (
"This is not a pipe");
472 otherLabels.
push_back (
"You should not see this");
475 for (size_type i = 0; i < labels.
size (); ++i) {
483 const size_t loopLength = 25;
484 for (
int k = 0; k < 3; ++k) {
485 for (size_type i = 0; i < timers.
size (); ++i) {
487 slowLoop (loopLength);
496 for (size_type i = 0; i < filters.
size (); ++i) {
498 std::ostringstream oss;
506 out << oss.str () << std::endl;
510 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
511 const size_t pos = oss.str ().find (outLabels[i][j]);
520 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
522 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
523 const size_t pos = oss.str ().find (outLabels[ii][j]);
530 for (size_type j = 0; j < otherLabels.
size(); ++j) {
531 const size_t pos = oss.str ().find (otherLabels[j]);
537 std::ostringstream oss;
540 reportParams->
set (
"Report format",
"YAML");
541 reportParams->
set (
"YAML style",
"compact");
547 out << oss.str () << std::endl;
551 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
552 const size_t pos = oss.str ().find (outLabels[i][j]);
561 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
563 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
564 const size_t pos = oss.str ().find (outLabels[ii][j]);
571 for (size_type j = 0; j < otherLabels.
size(); ++j) {
572 const size_t pos = oss.str ().find (otherLabels[j]);
578 std::ostringstream oss;
581 reportParams->
set (
"Report format",
"YAML");
582 reportParams->
set (
"YAML style",
"spacious");
588 out << oss.str () << std::endl;
592 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
593 const size_t pos = oss.str ().find (outLabels[i][j]);
602 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
604 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
605 const size_t pos = oss.str ().find (outLabels[ii][j]);
612 for (size_type j = 0; j < otherLabels.
size(); ++j) {
613 const size_t pos = oss.str ().find (otherLabels[j]);
642 using Teuchos::parameterList;
645 func_time_monitor2 ();
648 std::ostringstream oss;
654 out << oss.str() << std::endl;
656 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
658 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
663 std::ostringstream oss;
666 reportParams->
set (
"Report format",
"YAML");
667 reportParams->
set (
"YAML style",
"compact");
673 out << oss.str () << std::endl;
675 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
677 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
682 std::ostringstream oss;
685 reportParams->
set (
"Report format",
"YAML");
686 reportParams->
set (
"YAML style",
"spacious");
692 out << oss.str () << std::endl;
694 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
696 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
714 const int numProcs = comm->getSize ();
715 const int myRank = comm->getRank ();
722 int mpiHasBeenInitialized = 0;
723 MPI_Initialized (&mpiHasBeenInitialized);
724 if (! mpiHasBeenInitialized) {
731 std::ostringstream oss;
748 const size_t timerA_loopLength = 150;
749 const size_t timerB_loopLength = 200;
752 for (
size_t k = 0; k < 3; ++k) {
754 slowLoop (timerA_loopLength);
758 slowLoop (timerB_loopLength);
761 const bool alwaysWriteLocal =
false;
762 const bool writeGlobalStats =
true;
763 const bool writeZeroTimers =
true;
770 out << std::endl <<
"Testing intersection of timers:" << std::endl
771 << oss.str() << std::endl;
775 size_t substr_i = oss.str().find (
"Timer A");
778 substr_i = oss.str().find (
"Timer B");
783 std::ostringstream ossUnion;
785 writeZeroTimers,
Union);
790 out << std::endl <<
"Testing union of timers:" << std::endl
791 << ossUnion.str() << std::endl;
795 substr_i = ossUnion.str().find (
"Timer A");
797 substr_i = ossUnion.str().find (
"Timer B");
811 std::ostringstream oss;
825 const size_t timerA_loopLength = 200;
826 const size_t timerB_loopLength = 250;
829 for (
size_t k = 0; k < 3; ++k) {
831 slowLoop (
size_t (timerA_loopLength));
836 slowLoop (
size_t (timerB_loopLength));
839 const bool alwaysWriteLocal =
false;
840 const bool writeGlobalStats =
true;
841 const bool writeZeroTimers =
false;
848 out << oss.str() << std::endl;
851 size_t substr_i = oss.str().find (
"Timer A");
853 substr_i = oss.str().find (
"Timer B");
857 substr_i = oss.str().find (
"Timer C");
872 const int myRank = comm->getRank ();
879 int mpiHasBeenInitialized = 0;
880 MPI_Initialized (&mpiHasBeenInitialized);
881 if (! mpiHasBeenInitialized) {
888 std::ostringstream oss;
906 const size_t timerA_loopLength = 200;
907 const size_t timerB_loopLength = 500;
911 for (
int k = 0; k < 3; ++k) {
913 slowLoop (
size_t (timerA_loopLength));
920 slowLoop (
size_t (timerB_loopLength));
923 const bool alwaysWriteLocal =
false;
924 const bool writeGlobalStats =
true;
925 const bool writeZeroTimers =
false;
927 writeZeroTimers,
Union);
932 out << oss.str() << std::endl;
935 size_t substr_i = oss.str().find (
"Timer A");
937 substr_i = oss.str().find (
"Timer B");
941 substr_i = oss.str().find (
"Timer C");
954 const int myRank = comm->getRank ();
958 int mpiHasBeenInitialized = 0;
959 MPI_Initialized (&mpiHasBeenInitialized);
960 if (! mpiHasBeenInitialized) {
967 std::ostringstream oss;
969 std::string timerName=
"Timer Z";
1003 const bool alwaysWriteLocal =
false;
1004 const bool writeGlobalStats =
true;
1005 const bool writeZeroTimers =
false;
1006 bool ignoreMissingTimers =
false;
1007 std::string filter =
"";
1009 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1014 out << oss.str() << std::endl;
1016 if (comm->getSize() > 1) {
1018 size_t substr_i = oss.str().find (
"0 (0)");
1023 std::ostringstream oss2;
1025 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1026 out << oss2.str() << std::endl;
1027 if (comm->getSize() > 1) {
1029 size_t substr_i = oss2.str().find (
"0 (0)");
1037 ignoreMissingTimers =
true;
1038 std::ostringstream oss3;
1040 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1041 out << oss3.str() << std::endl;
1044 size_t substr_i = oss3.str().find (
"0 (0)");
1048 std::ostringstream oss4;
1050 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1051 out << oss4.str() << std::endl;
1053 substr_i = oss4.str().find (
"0 (0)");
#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.
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).
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
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="", const bool ignoreZeroTimers=false)
Print summary statistics for all timers on the given communicator.
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.
TEST_EQUALITY(rcp_dynamic_cast< const EnhancedNumberValidator< double > >(castedDep1->getValuesAndValidators().find("val1") ->second, true) ->getMax(), double1Vali->getMax())
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
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).
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...