28 #pragma comment(lib, "Ws2_32.lib")
29 # include <Winsock2.h>
37 #ifdef HAVE_TEUCHOSCORE_KOKKOS
38 #include "Kokkos_Core.hpp"
43 void func_time_monitor1()
49 void func_time_monitor2()
76 return fib (n-1) + fib (n-2);
86 slowLoop (
const size_t n)
88 const double inc = 1 /
static_cast<double> (
n);
91 for (
size_t i = 0; i <
n; ++i) {
92 for (
size_t j = 0; j <
n; ++j) {
93 for (
size_t k = 0; k <
n; ++k) {
112 using Teuchos::parameterList;
115 func_time_monitor1 ();
118 std::ostringstream oss;
124 out << oss.str () << std::endl;
128 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
134 std::ostringstream oss;
137 reportParams->
set (
"Report format",
"YAML");
138 reportParams->
set (
"YAML style",
"compact");
144 out << oss.str () << std::endl;
147 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
152 std::ostringstream oss;
155 reportParams->
set (
"Report format",
"YAML");
156 reportParams->
set (
"YAML style",
"spacious");
162 out << oss.str () << std::endl;
165 const size_t substr_i = oss.str ().find (
"FUNC_TIME_MONITOR1");
181 using Teuchos::parameterList;
183 using Teuchos::rcpFromRef;
189 out <<
"Testing TimeMonitor's disableTimer() and enableTimer() methods"
191 OSTab (rcpFromRef (out));
193 out <<
"Creating timers" << endl;
194 const int numTrials = 5;
195 const int numTimers = 3;
197 for (size_type i = 0; i < numTimers; ++i) {
198 std::ostringstream os;
203 out <<
"Running all timers without disabling any" << endl;
208 const size_t loopLength = 25;
209 for (
int k = 0; k < numTrials; ++k) {
210 for (size_type i = 0; i < numTimers; ++i) {
212 slowLoop (loopLength);
215 for (size_type i = 0; i < numTimers; ++i) {
219 out <<
"Disabling one timer and trying again" << endl;
222 for (
int k = 0; k < numTrials; ++k) {
223 for (size_type i = 0; i < numTimers; ++i) {
225 slowLoop (loopLength);
229 for (size_type i = 1; i < numTimers; ++i) {
233 out <<
"Reenabling the timer and trying again" << endl;
236 for (
int k = 0; k < numTrials; ++k) {
237 for (size_type i = 0; i < numTimers; ++i) {
239 slowLoop (loopLength);
243 for (size_type i = 1; i < numTimers; ++i) {
247 out <<
"Test that summarize() reports enabled and disabled timers" << endl;
253 std::ostringstream oss;
259 out << oss.str () << std::endl;
262 for (size_type i = 0; i < numTimers; ++i) {
263 const std::string name = timers[i]->name ();
265 const size_t substr_i = oss.str ().find (name);
283 using Teuchos::parameterList;
293 inputLabels.
push_back (
"NoQuotingNeeded");
294 inputLabels.
push_back (
"No quoting needed");
295 inputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
296 inputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
297 inputLabels.
push_back (
"\"Already quoted: quoting needed\"");
298 inputLabels.
push_back (
"NotQuoted:QuotingNeeded");
299 inputLabels.
push_back (
"Not quoted: quoting needed");
301 inputLabels.
push_back (
"Not quoted \" quoting needed");
302 inputLabels.
push_back (
"Not quoted \" \" quoting needed");
303 inputLabels.
push_back (
"\"Already quoted \" quoting needed\"");
304 inputLabels.
push_back (
"\"Already quoted \" \" quoting needed\"");
308 inputLabels.
push_back (
"Not quoted \\ quoting needed");
309 inputLabels.
push_back (
"Not quoted \\\\ quoting needed");
310 inputLabels.
push_back (
"Not quoted \\ \\ quoting needed");
311 inputLabels.
push_back (
"\"Already quoted \\ quoting needed\"");
312 inputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
313 inputLabels.
push_back (
"\"Already quoted \\ \\ quoting needed\"");
315 outputLabels.
push_back (
"NoQuotingNeeded");
316 outputLabels.
push_back (
"No quoting needed");
317 outputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
318 outputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
319 outputLabels.
push_back (
"\"Already quoted: quoting needed\"");
320 outputLabels.
push_back (
"\"NotQuoted:QuotingNeeded\"");
321 outputLabels.
push_back (
"\"Not quoted: quoting needed\"");
322 outputLabels.
push_back (
"\"Not quoted \\\" quoting needed\"");
323 outputLabels.
push_back (
"\"Not quoted \\\" \\\" quoting needed\"");
324 outputLabels.
push_back (
"\"Already quoted \\\" quoting needed\"");
325 outputLabels.
push_back (
"\"Already quoted \\\" \\\" quoting needed\"");
326 outputLabels.
push_back (
"\"Not quoted \\\\ quoting needed\"");
327 outputLabels.
push_back (
"\"Not quoted \\\\\\\\ quoting needed\"");
328 outputLabels.
push_back (
"\"Not quoted \\\\ \\\\ quoting needed\"");
329 outputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
330 outputLabels.
push_back (
"\"Already quoted \\\\\\\\ quoting needed\"");
331 outputLabels.
push_back (
"\"Already quoted \\\\ \\\\ quoting needed\"");
335 inputLabels.
size () != outputLabels.
size (),
337 "The number of input labels is different than the number of output labels."
338 " Please ask a Teuchos developer to make sure that every test input "
339 "label has a corresponding output label.");
342 for (size_type i = 0; i < inputLabels.
size (); ++i) {
350 const size_t loopLength = 25;
351 for (
int k = 0; k < 3; ++k) {
352 for (size_type i = 0; i < timers.size (); ++i) {
354 slowLoop (loopLength);
359 std::ostringstream oss;
362 reportParams->
set (
"Report format",
"YAML");
363 reportParams->
set (
"YAML style",
"compact");
369 out << oss.str () << std::endl;
372 for (size_type i = 0; i < inputLabels.
size(); ++i) {
373 const size_t pos = oss.str ().find (outputLabels[i]);
379 std::ostringstream oss;
382 reportParams->
set (
"Report format",
"YAML");
383 reportParams->
set (
"YAML style",
"spacious");
389 out << oss.str () << std::endl;
392 for (size_type i = 0; i < inputLabels.
size(); ++i) {
393 const size_t pos = oss.str ().find (outputLabels[i]);
410 using Teuchos::parameterList;
431 labels.
push_back (
"You should not see this");
447 otherLabels.
push_back (
"This is not a pipe");
448 otherLabels.
push_back (
"You should not see this");
451 for (size_type i = 0; i < labels.
size (); ++i) {
459 const size_t loopLength = 25;
460 for (
int k = 0; k < 3; ++k) {
461 for (size_type i = 0; i < timers.
size (); ++i) {
463 slowLoop (loopLength);
472 for (size_type i = 0; i < filters.
size (); ++i) {
474 std::ostringstream oss;
482 out << oss.str () << std::endl;
487 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
488 const size_t pos = oss.str ().find (outLabels[i][j]);
498 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
500 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
501 const size_t pos = oss.str ().find (outLabels[ii][j]);
508 for (size_type j = 0; j < otherLabels.
size(); ++j) {
509 const size_t pos = oss.str ().find (otherLabels[j]);
515 std::ostringstream oss;
518 reportParams->
set (
"Report format",
"YAML");
519 reportParams->
set (
"YAML style",
"compact");
525 out << oss.str () << std::endl;
529 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
530 const size_t pos = oss.str ().find (outLabels[i][j]);
539 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
541 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
542 const size_t pos = oss.str ().find (outLabels[ii][j]);
549 for (size_type j = 0; j < otherLabels.
size(); ++j) {
550 const size_t pos = oss.str ().find (otherLabels[j]);
556 std::ostringstream oss;
559 reportParams->
set (
"Report format",
"YAML");
560 reportParams->
set (
"YAML style",
"spacious");
566 out << oss.str () << std::endl;
570 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
571 const size_t pos = oss.str ().find (outLabels[i][j]);
580 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
582 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
583 const size_t pos = oss.str ().find (outLabels[ii][j]);
590 for (size_type j = 0; j < otherLabels.
size(); ++j) {
591 const size_t pos = oss.str ().find (otherLabels[j]);
620 using Teuchos::parameterList;
623 func_time_monitor2 ();
626 std::ostringstream oss;
632 out << oss.str() << std::endl;
635 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
637 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
643 std::ostringstream oss;
646 reportParams->
set (
"Report format",
"YAML");
647 reportParams->
set (
"YAML style",
"compact");
653 out << oss.str () << std::endl;
655 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
657 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
662 std::ostringstream oss;
665 reportParams->
set (
"Report format",
"YAML");
666 reportParams->
set (
"YAML style",
"spacious");
672 out << oss.str () << std::endl;
674 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
676 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
694 const int numProcs = comm->getSize ();
695 const int myRank = comm->getRank ();
702 int mpiHasBeenInitialized = 0;
703 MPI_Initialized (&mpiHasBeenInitialized);
704 if (! mpiHasBeenInitialized) {
711 std::ostringstream oss;
728 const size_t timerA_loopLength = 150;
729 const size_t timerB_loopLength = 200;
732 for (
size_t k = 0; k < 3; ++k) {
734 slowLoop (timerA_loopLength);
738 slowLoop (timerB_loopLength);
741 const bool alwaysWriteLocal =
false;
742 const bool writeGlobalStats =
true;
743 const bool writeZeroTimers =
true;
750 out << std::endl <<
"Testing intersection of timers:" << std::endl
751 << oss.str() << std::endl;
756 size_t substr_i = oss.str().find (
"Timer A");
759 substr_i = oss.str().find (
"Timer B");
765 std::ostringstream ossUnion;
767 writeZeroTimers,
Union);
772 out << std::endl <<
"Testing union of timers:" << std::endl
773 << ossUnion.str() << std::endl;
778 size_t substr_i = ossUnion.str().find (
"Timer A");
780 substr_i = ossUnion.str().find (
"Timer B");
795 std::ostringstream oss;
809 const size_t timerA_loopLength = 200;
810 const size_t timerB_loopLength = 250;
813 for (
size_t k = 0; k < 3; ++k) {
815 slowLoop (
size_t (timerA_loopLength));
820 slowLoop (
size_t (timerB_loopLength));
823 const bool alwaysWriteLocal =
false;
824 const bool writeGlobalStats =
true;
825 const bool writeZeroTimers =
false;
832 out << oss.str() << std::endl;
836 size_t substr_i = oss.str().find (
"Timer A");
838 substr_i = oss.str().find (
"Timer B");
842 substr_i = oss.str().find (
"Timer C");
858 const int myRank = comm->getRank ();
865 int mpiHasBeenInitialized = 0;
866 MPI_Initialized (&mpiHasBeenInitialized);
867 if (! mpiHasBeenInitialized) {
874 std::ostringstream oss;
892 const size_t timerA_loopLength = 200;
893 const size_t timerB_loopLength = 500;
897 for (
int k = 0; k < 3; ++k) {
899 slowLoop (
size_t (timerA_loopLength));
906 slowLoop (
size_t (timerB_loopLength));
909 const bool alwaysWriteLocal =
false;
910 const bool writeGlobalStats =
true;
911 const bool writeZeroTimers =
false;
913 writeZeroTimers,
Union);
918 out << oss.str() << std::endl;
922 size_t substr_i = oss.str().find (
"Timer A");
924 substr_i = oss.str().find (
"Timer B");
928 substr_i = oss.str().find (
"Timer C");
942 const int myRank = comm->getRank ();
946 int mpiHasBeenInitialized = 0;
947 MPI_Initialized (&mpiHasBeenInitialized);
948 if (! mpiHasBeenInitialized) {
955 std::ostringstream oss;
957 std::string timerName=
"Timer Z";
991 const bool alwaysWriteLocal =
false;
992 const bool writeGlobalStats =
true;
993 const bool writeZeroTimers =
false;
994 bool ignoreMissingTimers =
false;
995 std::string filter =
"";
997 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1002 out << oss.str() << std::endl;
1004 if (comm->getSize() > 1) {
1007 size_t substr_i = oss.str().find (
"0 (0)");
1013 std::ostringstream oss2;
1015 writeZeroTimers, Union, filter, ignoreMissingTimers);
1016 out << oss2.str() << std::endl;
1017 if (comm->getSize() > 1) {
1020 size_t substr_i = oss2.str().find (
"0 (0)");
1029 ignoreMissingTimers =
true;
1030 std::ostringstream oss3;
1032 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1033 out << oss3.str() << std::endl;
1036 size_t substr_i = oss3.str().find (
"0 (0)");
1040 std::ostringstream oss4;
1042 writeZeroTimers, Union, filter, ignoreMissingTimers);
1043 out << oss4.str() << std::endl;
1045 substr_i = oss4.str().find (
"0 (0)");
1056 #ifdef HAVE_TEUCHOSCORE_KOKKOS
1057 namespace KokkosFenceCounter
1059 static int numFences;
1066 void begin_fence_callback(
const char*,
const uint32_t deviceId, uint64_t*) {
1067 using namespace Kokkos::Tools::Experimental;
1070 DeviceType fenceDevice = identifier_from_devid(deviceId).type;
1071 DeviceType defaultDevice = DeviceTypeTraits<Kokkos::DefaultExecutionSpace>::id;
1072 if(fenceDevice == defaultDevice)
1083 KokkosFenceCounter::reset();
1084 Kokkos::Tools::Experimental::set_begin_fence_callback(KokkosFenceCounter::begin_fence_callback);
1085 int fenceCountAfterStart = 0;
1086 int fenceCountAfterStop = 0;
1090 TimeMonitor monitor (*timer);
1092 fenceCountAfterStart = KokkosFenceCounter::numFences;
1095 fenceCountAfterStop = KokkosFenceCounter::numFences;
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.
#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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
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.
static bool fenceTimers()
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 guard for Teuchos::Time, with MPI collective timer reporting.
Smart reference counting pointer class for automatic garbage collection.
static void enableTimer(const std::string &name)
Enable the timer with the given name.
Scope guard for Time, that can compute MPI collective 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...