27 #pragma comment(lib, "Ws2_32.lib")
28 # include <Winsock2.h>
36 #ifdef HAVE_TEUCHOS_TIMER_KOKKOS_FENCE
37 #include "Kokkos_Core.hpp"
42 void func_time_monitor1()
48 void func_time_monitor2()
75 return fib (n-1) + fib (n-2);
85 slowLoop (
const size_t n)
87 const double inc = 1 /
static_cast<double> (
n);
90 for (
size_t i = 0; i <
n; ++i) {
91 for (
size_t j = 0; j <
n; ++j) {
92 for (
size_t k = 0; k <
n; ++k) {
111 using Teuchos::parameterList;
114 func_time_monitor1 ();
117 std::ostringstream oss;
123 out << oss.str () << std::endl;
127 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 ();
264 const size_t substr_i = oss.str ().find (name);
282 using Teuchos::parameterList;
292 inputLabels.
push_back (
"NoQuotingNeeded");
293 inputLabels.
push_back (
"No quoting needed");
294 inputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
295 inputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
296 inputLabels.
push_back (
"\"Already quoted: quoting needed\"");
297 inputLabels.
push_back (
"NotQuoted:QuotingNeeded");
298 inputLabels.
push_back (
"Not quoted: quoting needed");
300 inputLabels.
push_back (
"Not quoted \" quoting needed");
301 inputLabels.
push_back (
"Not quoted \" \" quoting needed");
302 inputLabels.
push_back (
"\"Already quoted \" quoting needed\"");
303 inputLabels.
push_back (
"\"Already quoted \" \" quoting needed\"");
307 inputLabels.
push_back (
"Not quoted \\ quoting needed");
308 inputLabels.
push_back (
"Not quoted \\\\ quoting needed");
309 inputLabels.
push_back (
"Not quoted \\ \\ quoting needed");
310 inputLabels.
push_back (
"\"Already quoted \\ quoting needed\"");
311 inputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
312 inputLabels.
push_back (
"\"Already quoted \\ \\ quoting needed\"");
314 outputLabels.
push_back (
"NoQuotingNeeded");
315 outputLabels.
push_back (
"No quoting needed");
316 outputLabels.
push_back (
"\"AlreadyQuotedNoQuotingNeeded\"");
317 outputLabels.
push_back (
"\"Already quoted, no quoting needed\"");
318 outputLabels.
push_back (
"\"Already quoted: quoting needed\"");
319 outputLabels.
push_back (
"\"NotQuoted:QuotingNeeded\"");
320 outputLabels.
push_back (
"\"Not quoted: quoting needed\"");
321 outputLabels.
push_back (
"\"Not quoted \\\" quoting needed\"");
322 outputLabels.
push_back (
"\"Not quoted \\\" \\\" quoting needed\"");
323 outputLabels.
push_back (
"\"Already quoted \\\" quoting needed\"");
324 outputLabels.
push_back (
"\"Already quoted \\\" \\\" quoting needed\"");
325 outputLabels.
push_back (
"\"Not quoted \\\\ quoting needed\"");
326 outputLabels.
push_back (
"\"Not quoted \\\\\\\\ quoting needed\"");
327 outputLabels.
push_back (
"\"Not quoted \\\\ \\\\ quoting needed\"");
328 outputLabels.
push_back (
"\"Already quoted \\\\ quoting needed\"");
329 outputLabels.
push_back (
"\"Already quoted \\\\\\\\ quoting needed\"");
330 outputLabels.
push_back (
"\"Already quoted \\\\ \\\\ quoting needed\"");
334 inputLabels.
size () != outputLabels.
size (),
336 "The number of input labels is different than the number of output labels."
337 " Please ask a Teuchos developer to make sure that every test input "
338 "label has a corresponding output label.");
341 for (size_type i = 0; i < inputLabels.
size (); ++i) {
349 const size_t loopLength = 25;
350 for (
int k = 0; k < 3; ++k) {
351 for (size_type i = 0; i < timers.size (); ++i) {
353 slowLoop (loopLength);
358 std::ostringstream oss;
361 reportParams->
set (
"Report format",
"YAML");
362 reportParams->
set (
"YAML style",
"compact");
368 out << oss.str () << std::endl;
371 for (size_type i = 0; i < inputLabels.
size(); ++i) {
372 const size_t pos = oss.str ().find (outputLabels[i]);
378 std::ostringstream oss;
381 reportParams->
set (
"Report format",
"YAML");
382 reportParams->
set (
"YAML style",
"spacious");
388 out << oss.str () << std::endl;
391 for (size_type i = 0; i < inputLabels.
size(); ++i) {
392 const size_t pos = oss.str ().find (outputLabels[i]);
409 using Teuchos::parameterList;
430 labels.
push_back (
"You should not see this");
446 otherLabels.
push_back (
"This is not a pipe");
447 otherLabels.
push_back (
"You should not see this");
450 for (size_type i = 0; i < labels.
size (); ++i) {
458 const size_t loopLength = 25;
459 for (
int k = 0; k < 3; ++k) {
460 for (size_type i = 0; i < timers.
size (); ++i) {
462 slowLoop (loopLength);
471 for (size_type i = 0; i < filters.
size (); ++i) {
473 std::ostringstream oss;
481 out << oss.str () << std::endl;
486 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
487 const size_t pos = oss.str ().find (outLabels[i][j]);
497 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
499 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
500 const size_t pos = oss.str ().find (outLabels[ii][j]);
507 for (size_type j = 0; j < otherLabels.
size(); ++j) {
508 const size_t pos = oss.str ().find (otherLabels[j]);
514 std::ostringstream oss;
517 reportParams->
set (
"Report format",
"YAML");
518 reportParams->
set (
"YAML style",
"compact");
524 out << oss.str () << std::endl;
528 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
529 const size_t pos = oss.str ().find (outLabels[i][j]);
538 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
540 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
541 const size_t pos = oss.str ().find (outLabels[ii][j]);
548 for (size_type j = 0; j < otherLabels.
size(); ++j) {
549 const size_t pos = oss.str ().find (otherLabels[j]);
555 std::ostringstream oss;
558 reportParams->
set (
"Report format",
"YAML");
559 reportParams->
set (
"YAML style",
"spacious");
565 out << oss.str () << std::endl;
569 for (size_type j = 0; j < outLabels[i].
size(); ++j) {
570 const size_t pos = oss.str ().find (outLabels[i][j]);
579 for (size_type ii = 0; ii < outLabels.
size(); ++ii) {
581 for (size_type j = 0; j < outLabels[ii].
size(); ++j) {
582 const size_t pos = oss.str ().find (outLabels[ii][j]);
589 for (size_type j = 0; j < otherLabels.
size(); ++j) {
590 const size_t pos = oss.str ().find (otherLabels[j]);
619 using Teuchos::parameterList;
622 func_time_monitor2 ();
625 std::ostringstream oss;
631 out << oss.str() << std::endl;
634 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
636 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
642 std::ostringstream oss;
645 reportParams->
set (
"Report format",
"YAML");
646 reportParams->
set (
"YAML style",
"compact");
652 out << oss.str () << std::endl;
654 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
656 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
661 std::ostringstream oss;
664 reportParams->
set (
"Report format",
"YAML");
665 reportParams->
set (
"YAML style",
"spacious");
671 out << oss.str () << std::endl;
673 const size_t substr_i = oss.str().find (
"FUNC_TIME_MONITOR2");
675 const size_t substr_inner_i = oss.str().find (
"FUNC_TIME_MONITOR2_inner");
693 const int numProcs = comm->getSize ();
694 const int myRank = comm->getRank ();
701 int mpiHasBeenInitialized = 0;
702 MPI_Initialized (&mpiHasBeenInitialized);
703 if (! mpiHasBeenInitialized) {
710 std::ostringstream oss;
727 const size_t timerA_loopLength = 150;
728 const size_t timerB_loopLength = 200;
731 for (
size_t k = 0; k < 3; ++k) {
733 slowLoop (timerA_loopLength);
737 slowLoop (timerB_loopLength);
740 const bool alwaysWriteLocal =
false;
741 const bool writeGlobalStats =
true;
742 const bool writeZeroTimers =
true;
749 out << std::endl <<
"Testing intersection of timers:" << std::endl
750 << oss.str() << std::endl;
755 size_t substr_i = oss.str().find (
"Timer A");
758 substr_i = oss.str().find (
"Timer B");
764 std::ostringstream ossUnion;
766 writeZeroTimers,
Union);
771 out << std::endl <<
"Testing union of timers:" << std::endl
772 << ossUnion.str() << std::endl;
777 size_t substr_i = ossUnion.str().find (
"Timer A");
779 substr_i = ossUnion.str().find (
"Timer B");
794 std::ostringstream oss;
808 const size_t timerA_loopLength = 200;
809 const size_t timerB_loopLength = 250;
812 for (
size_t k = 0; k < 3; ++k) {
814 slowLoop (
size_t (timerA_loopLength));
819 slowLoop (
size_t (timerB_loopLength));
822 const bool alwaysWriteLocal =
false;
823 const bool writeGlobalStats =
true;
824 const bool writeZeroTimers =
false;
831 out << oss.str() << std::endl;
835 size_t substr_i = oss.str().find (
"Timer A");
837 substr_i = oss.str().find (
"Timer B");
841 substr_i = oss.str().find (
"Timer C");
857 const int myRank = comm->getRank ();
864 int mpiHasBeenInitialized = 0;
865 MPI_Initialized (&mpiHasBeenInitialized);
866 if (! mpiHasBeenInitialized) {
873 std::ostringstream oss;
891 const size_t timerA_loopLength = 200;
892 const size_t timerB_loopLength = 500;
896 for (
int k = 0; k < 3; ++k) {
898 slowLoop (
size_t (timerA_loopLength));
905 slowLoop (
size_t (timerB_loopLength));
908 const bool alwaysWriteLocal =
false;
909 const bool writeGlobalStats =
true;
910 const bool writeZeroTimers =
false;
912 writeZeroTimers,
Union);
917 out << oss.str() << std::endl;
921 size_t substr_i = oss.str().find (
"Timer A");
923 substr_i = oss.str().find (
"Timer B");
927 substr_i = oss.str().find (
"Timer C");
941 const int myRank = comm->getRank ();
945 int mpiHasBeenInitialized = 0;
946 MPI_Initialized (&mpiHasBeenInitialized);
947 if (! mpiHasBeenInitialized) {
954 std::ostringstream oss;
956 std::string timerName=
"Timer Z";
990 const bool alwaysWriteLocal =
false;
991 const bool writeGlobalStats =
true;
992 const bool writeZeroTimers =
false;
993 bool ignoreMissingTimers =
false;
994 std::string filter =
"";
996 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1001 out << oss.str() << std::endl;
1003 if (comm->getSize() > 1) {
1006 size_t substr_i = oss.str().find (
"0 (0)");
1012 std::ostringstream oss2;
1014 writeZeroTimers, Union, filter, ignoreMissingTimers);
1015 out << oss2.str() << std::endl;
1016 if (comm->getSize() > 1) {
1019 size_t substr_i = oss2.str().find (
"0 (0)");
1028 ignoreMissingTimers =
true;
1029 std::ostringstream oss3;
1031 writeZeroTimers,
Union, filter, ignoreMissingTimers);
1032 out << oss3.str() << std::endl;
1035 size_t substr_i = oss3.str().find (
"0 (0)");
1039 std::ostringstream oss4;
1041 writeZeroTimers, Union, filter, ignoreMissingTimers);
1042 out << oss4.str() << std::endl;
1044 substr_i = oss4.str().find (
"0 (0)");
1055 #ifdef HAVE_TEUCHOS_TIMER_KOKKOS_FENCE
1056 namespace KokkosFenceCounter
1058 static int numFences;
1065 void begin_fence_callback(
const char*,
const uint32_t deviceId, uint64_t*) {
1066 using namespace Kokkos::Tools::Experimental;
1069 DeviceType fenceDevice = identifier_from_devid(deviceId).type;
1070 DeviceType defaultDevice = DeviceTypeTraits<Kokkos::DefaultExecutionSpace>::id;
1071 if(fenceDevice == defaultDevice)
1082 KokkosFenceCounter::reset();
1083 Kokkos::Tools::Experimental::set_begin_fence_callback(KokkosFenceCounter::begin_fence_callback);
1084 int fenceCountAfterStart = 0;
1085 int fenceCountAfterStop = 0;
1089 TimeMonitor monitor (*timer);
1091 fenceCountAfterStart = KokkosFenceCounter::numFences;
1094 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.
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...