Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeMonitor_Issue3868.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
13 #include "Teuchos_CommHelpers.hpp"
14 #ifdef HAVE_TEUCHOS_MPI
16 #endif // HAVE_TEUCHOS_MPI
17 
18 TEUCHOS_UNIT_TEST(TimeMonitor, Issue3868) {
20  using Teuchos::Comm;
21  using Teuchos::outArg;
22  using Teuchos::RCP;
23  using Teuchos::REDUCE_MAX;
24  using Teuchos::reduceAll;
25 
26  RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm ();
27 
28  const int numProcs = comm->getSize ();
29  TEST_ASSERT( numProcs > 1 );
30  if (numProcs < 4) {
31  out << "This test requires at least 4 MPI processes." << std::endl;
32  return;
33  }
34 
35  const int myRank = comm->getRank();
36 
37  if (myRank == 3) {
38  Teuchos::TimeMonitor timer(*Teuchos::TimeMonitor::getNewTimer(std::string("myTimer")));
39  }
40 
41  std::ostringstream out1;
42  Teuchos::TimeMonitor::summarize(out1,false,true,false,Teuchos::Union,"",true);
43  int test = (out1.str().find("myTimer") != std::string::npos);
44 
45  int gblTest = false; // output argument
46  reduceAll<int, int> (*comm, REDUCE_MAX, test, outArg (gblTest));
47  TEST_EQUALITY(gblTest, 1);
48 
49 }
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Return the default global communicator.
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="", const bool ignoreZeroTimers=false)
Print summary statistics for all timers on the given communicator.
Unit testing support.
Implementation of Teuchos wrappers for MPI.
void reduceAll< int, int >(const Comm< int > &comm, const EReductionType reductType, const int count, const int sendBuffer[], int globalReducts[])
Abstract interface for distributed-memory communication.
Scope guard for Teuchos::Time, with MPI collective timer reporting.
Smart reference counting pointer class for automatic garbage collection.
Ptr< T > outArg(T &arg)
create a non-persisting (required or optional) output argument for a function call.
Scope guard for Time, that can compute MPI collective timer statistics.