61 #pragma comment(lib, "Ws2_32.lib")
62 # include <Winsock2.h>
72 void func_time_monitor1()
78 void func_time_monitor2()
105 return fib (n-1) + fib (n-2);
115 slowLoop (
const size_t n)
117 const double inc = 1 /
static_cast<double> (
n);
120 for (
size_t i = 0; i <
n; ++i) {
121 for (
size_t j = 0; j <
n; ++j) {
122 for (
size_t k = 0; k <
n; ++k) {
141 using Teuchos::parameterList;
144 func_time_monitor1 ();
147 std::ostringstream oss;
153 out << oss.str () << std::endl;
157 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
163 std::ostringstream oss;
166 reportParams->
set (
"Report format",
"YAML");
167 reportParams->
set (
"YAML style",
"compact");
173 out << oss.str () << std::endl;
176 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
181 std::ostringstream oss;
184 reportParams->
set (
"Report format",
"YAML");
185 reportParams->
set (
"YAML style",
"spacious");
191 out << oss.str () << std::endl;
194 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
210 using Teuchos::parameterList;
212 using Teuchos::rcpFromRef;
218 out <<
"Testing TimeMonitor's disableTimer() and enableTimer() methods"
220 OSTab (rcpFromRef (out));
222 out <<
"Creating timers" << endl;
223 const int numTrials = 5;
224 const int numTimers = 3;
226 for (size_type i = 0; i < numTimers; ++i) {
227 std::ostringstream os;
232 out <<
"Running all timers without disabling any" << endl;
237 const size_t loopLength = 25;
238 for (
int k = 0; k < numTrials; ++k) {
239 for (size_type i = 0; i < numTimers; ++i) {
241 slowLoop (loopLength);
244 for (size_type i = 0; i < numTimers; ++i) {
248 out <<
"Disabling one timer and trying again" << endl;
251 for (
int k = 0; k < numTrials; ++k) {
252 for (size_type i = 0; i < numTimers; ++i) {
254 slowLoop (loopLength);
258 for (size_type i = 1; i < numTimers; ++i) {
262 out <<
"Reenabling the timer and trying again" << endl;
265 for (
int k = 0; k < numTrials; ++k) {
266 for (size_type i = 0; i < numTimers; ++i) {
268 slowLoop (loopLength);
272 for (size_type i = 1; i < numTimers; ++i) {
276 out <<
"Test that summarize() reports enabled and disabled timers" << endl;
282 std::ostringstream oss;
288 out << oss.str () << std::endl;
291 for (size_type i = 0; i < numTimers; ++i) {
292 const std::string name = timers[i]->name ();
294 const size_t substr_i = oss.str ().find (name);
312 using Teuchos::parameterList;
322 inputLabels.
push_back (
"NoQuotingNeeded");
323 inputLabels.
push_back (
"No quoting needed");
324 inputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
325 inputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
326 inputLabels.
push_back (
"\"Already quoted: quoting needed\"");
327 inputLabels.
push_back (
"NotQuoted:QuotingNeeded");
328 inputLabels.
push_back (
"Not quoted: quoting needed");
330 inputLabels.
push_back (
"Not quoted \" quoting needed");
331 inputLabels.
push_back (
"Not quoted \" \" quoting needed");
332 inputLabels.
push_back (
"\"Already quoted \" quoting needed\"");
333 inputLabels.
push_back (
"\"Already quoted \" \" quoting needed\"");
337 inputLabels.
push_back (
"Not quoted \\ quoting needed");
338 inputLabels.
push_back (
"Not quoted \\\\ quoting needed");
339 inputLabels.
push_back (
"Not quoted \\ \\ quoting needed");
340 inputLabels.
push_back (
"\"Already quoted \\ quoting needed\"");
341 inputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
342 inputLabels.
push_back (
"\"Already quoted \\ \\ quoting needed\"");
344 outputLabels.
push_back (
"NoQuotingNeeded");
345 outputLabels.
push_back (
"No quoting needed");
346 outputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
347 outputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
348 outputLabels.
push_back (
"\"Already quoted: quoting needed\"");
349 outputLabels.
push_back (
"\"NotQuoted:QuotingNeeded\"");
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 (
"\"Not quoted \\\\ quoting needed\"");
356 outputLabels.
push_back (
"\"Not quoted \\\\\\\\ quoting needed\"");
357 outputLabels.
push_back (
"\"Not quoted \\\\ \\\\ quoting needed\"");
358 outputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
359 outputLabels.
push_back (
"\"Already quoted \\\\\\\\ quoting needed\"");
360 outputLabels.
push_back (
"\"Already quoted \\\\ \\\\ quoting needed\"");
364 inputLabels.
size () != outputLabels.
size (),
366 "The number of input labels is different than the number of output labels."
367 " Please ask a Teuchos developer to make sure that every test input "
368 "label has a corresponding output label.");
371 for (size_type i = 0; i < inputLabels.
size (); ++i) {
379 const size_t loopLength = 25;
380 for (
int k = 0; k < 3; ++k) {
381 for (size_type i = 0; i < timers.size (); ++i) {
383 slowLoop (loopLength);
388 std::ostringstream oss;
391 reportParams->
set (
"Report format",
"YAML");
392 reportParams->
set (
"YAML style",
"compact");
398 out << oss.str () << std::endl;
401 for (size_type i = 0; i < inputLabels.
size(); ++i) {
402 const size_t pos = oss.str ().find (outputLabels[i]);
408 std::ostringstream oss;
411 reportParams->
set (
"Report format",
"YAML");
412 reportParams->
set (
"YAML style",
"spacious");
418 out << oss.str () << std::endl;
421 for (size_type i = 0; i < inputLabels.
size(); ++i) {
422 const size_t pos = oss.str ().find (outputLabels[i]);
439 using Teuchos::parameterList;
460 labels.
push_back (
"You should not see this");
476 otherLabels.
push_back (
"This is not a pipe");
477 otherLabels.
push_back (
"You should not see this");
480 for (size_type i = 0; i < labels.
size (); ++i) {
488 const size_t loopLength = 25;
489 for (
int k = 0; k < 3; ++k) {
490 for (size_type i = 0; i < timers.
size (); ++i) {
492 slowLoop (loopLength);
501 for (size_type i = 0; i < filters.
size (); ++i) {
503 std::ostringstream oss;
511 out << oss.str () << std::endl;
516 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
517 const size_t pos = oss.str ().find (outLabels[i][j]);
527 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
529 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
530 const size_t pos = oss.str ().find (outLabels[ii][j]);
537 for (size_type j = 0; j < otherLabels.
size(); ++j) {
538 const size_t pos = oss.str ().find (otherLabels[j]);
544 std::ostringstream oss;
547 reportParams->
set (
"Report format",
"YAML");
548 reportParams->
set (
"YAML style",
"compact");
554 out << oss.str () << std::endl;
558 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
559 const size_t pos = oss.str ().find (outLabels[i][j]);
568 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
570 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
571 const size_t pos = oss.str ().find (outLabels[ii][j]);
578 for (size_type j = 0; j < otherLabels.
size(); ++j) {
579 const size_t pos = oss.str ().find (otherLabels[j]);
585 std::ostringstream oss;
588 reportParams->
set (
"Report format",
"YAML");
589 reportParams->
set (
"YAML style",
"spacious");
595 out << oss.str () << std::endl;
599 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
600 const size_t pos = oss.str ().find (outLabels[i][j]);
609 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
611 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
612 const size_t pos = oss.str ().find (outLabels[ii][j]);
619 for (size_type j = 0; j < otherLabels.
size(); ++j) {
620 const size_t pos = oss.str ().find (otherLabels[j]);
649 using Teuchos::parameterList;
652 func_time_monitor2 ();
655 std::ostringstream oss;
661 out << oss.str() << std::endl;
664 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
666 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
672 std::ostringstream oss;
675 reportParams->
set (
"Report format",
"YAML");
676 reportParams->
set (
"YAML style",
"compact");
682 out << oss.str () << std::endl;
684 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
686 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
691 std::ostringstream oss;
694 reportParams->
set (
"Report format",
"YAML");
695 reportParams->
set (
"YAML style",
"spacious");
701 out << oss.str () << std::endl;
703 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
705 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
723 const int numProcs = comm->getSize ();
724 const int myRank = comm->getRank ();
731 int mpiHasBeenInitialized = 0;
732 MPI_Initialized (&mpiHasBeenInitialized);
733 if (! mpiHasBeenInitialized) {
740 std::ostringstream oss;
757 const size_t timerA_loopLength = 150;
758 const size_t timerB_loopLength = 200;
761 for (
size_t k = 0; k < 3; ++k) {
763 slowLoop (timerA_loopLength);
767 slowLoop (timerB_loopLength);
770 const bool alwaysWriteLocal =
false;
771 const bool writeGlobalStats =
true;
772 const bool writeZeroTimers =
true;
779 out << std::endl <<
"Testing intersection of timers:" << std::endl
780 << oss.str() << std::endl;
785 size_t substr_i = oss.str().find (
"Timer A");
788 substr_i = oss.str().find (
"Timer B");
794 std::ostringstream ossUnion;
796 writeZeroTimers,
Union);
801 out << std::endl <<
"Testing union of timers:" << std::endl
802 << ossUnion.str() << std::endl;
807 size_t substr_i = ossUnion.str().find (
"Timer A");
809 substr_i = ossUnion.str().find (
"Timer B");
824 std::ostringstream oss;
838 const size_t timerA_loopLength = 200;
839 const size_t timerB_loopLength = 250;
842 for (
size_t k = 0; k < 3; ++k) {
844 slowLoop (
size_t (timerA_loopLength));
849 slowLoop (
size_t (timerB_loopLength));
852 const bool alwaysWriteLocal =
false;
853 const bool writeGlobalStats =
true;
854 const bool writeZeroTimers =
false;
861 out << oss.str() << std::endl;
865 size_t substr_i = oss.str().find (
"Timer A");
867 substr_i = oss.str().find (
"Timer B");
871 substr_i = oss.str().find (
"Timer C");
887 const int myRank = comm->getRank ();
894 int mpiHasBeenInitialized = 0;
895 MPI_Initialized (&mpiHasBeenInitialized);
896 if (! mpiHasBeenInitialized) {
903 std::ostringstream oss;
921 const size_t timerA_loopLength = 200;
922 const size_t timerB_loopLength = 500;
926 for (
int k = 0; k < 3; ++k) {
928 slowLoop (
size_t (timerA_loopLength));
935 slowLoop (
size_t (timerB_loopLength));
938 const bool alwaysWriteLocal =
false;
939 const bool writeGlobalStats =
true;
940 const bool writeZeroTimers =
false;
942 writeZeroTimers,
Union);
947 out << oss.str() << std::endl;
951 size_t substr_i = oss.str().find (
"Timer A");
953 substr_i = oss.str().find (
"Timer B");
957 substr_i = oss.str().find (
"Timer C");
971 const int myRank = comm->getRank ();
975 int mpiHasBeenInitialized = 0;
976 MPI_Initialized (&mpiHasBeenInitialized);
977 if (! mpiHasBeenInitialized) {
984 std::ostringstream oss;
986 std::string timerName=
"Timer Z";
1020 const bool alwaysWriteLocal =
false;
1021 const bool writeGlobalStats =
true;
1022 const bool writeZeroTimers =
false;
1023 bool ignoreMissingTimers =
false;
1024 std::string filter =
"";
1026 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1031 out << oss.str() << std::endl;
1033 if (comm->getSize() > 1) {
1036 size_t substr_i = oss.str().find (
"0 (0)");
1042 std::ostringstream oss2;
1044 writeZeroTimers, Union, filter, ignoreMissingTimers);
1045 out << oss2.str() << std::endl;
1046 if (comm->getSize() > 1) {
1049 size_t substr_i = oss2.str().find (
"0 (0)");
1058 ignoreMissingTimers =
true;
1059 std::ostringstream oss3;
1061 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1062 out << oss3.str() << std::endl;
1065 size_t substr_i = oss3.str().find (
"0 (0)");
1069 std::ostringstream oss4;
1071 writeZeroTimers, Union, filter, ignoreMissingTimers);
1072 out << oss4.str() << std::endl;
1074 substr_i = oss4.str().find (
"0 (0)");
static int getRank()
The rank of the calling process in MPI_COMM_WORLD.
#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).
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.
Ptr< T > ptr() const
Get a safer wrapper raw C++ pointer to the underlying object.
A list of parameters of arbitrary type.
void push_back(const value_type &x)
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
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).
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...