Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Teuchos_TimeMonitor.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Teuchos: Common Tools Package
5// Copyright (2004) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// ***********************************************************************
38// @HEADER
39
40#ifndef TEUCHOS_TIMEMONITOR_HPP
41#define TEUCHOS_TIMEMONITOR_HPP
42
43
60
65
68#include "Teuchos_Comm.hpp"
69#include "Teuchos_Time.hpp"
70
72
77#define TEUCHOS_TIMER(funcName, strName) \
78 static Teuchos::Time& funcName() \
79 {static Teuchos::RCP<Time> rtn = \
80 Teuchos::TimeMonitor::getNewCounter(strName); return *rtn;}
81
82
91#define TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, DIFF ) \
92 static Teuchos::RCP<Teuchos::Time> DIFF ## blabla_localTimer; \
93 if(!DIFF ## blabla_localTimer.get()) { \
94 std::ostringstream oss; \
95 oss << FUNCNAME; \
96 DIFF ## blabla_localTimer = Teuchos::TimeMonitor::getNewCounter(oss.str()); \
97 } \
98 Teuchos::TimeMonitor DIFF ## blabla_localTimeMonitor(*DIFF ## blabla_localTimer)
99
100
123#define TEUCHOS_FUNC_TIME_MONITOR( FUNCNAME ) \
124 TEUCHOS_FUNC_TIME_MONITOR_DIFF( FUNCNAME, main )
125
126
127namespace Teuchos {
128
129// Forward declaration
130class StackedTimer;
131
143typedef std::map<std::string, std::vector<std::pair<double, double> > > stat_map_type;
144
179 public PerformanceMonitorBase<Time> {
180public:
181
184
193 TimeMonitor (Time& timer, bool reset=false);
194
196 TimeMonitor () = delete;
197
199 ~TimeMonitor() override;
201
210 static RCP<Time> getNewTimer (const std::string& name) {
211 return getNewCounter (name);
212 }
213
229 static void disableTimer (const std::string& name);
230
239 static void enableTimer (const std::string& name);
240
247 static void zeroOutTimers();
248
364 static void
365 computeGlobalTimerStatistics (stat_map_type& statData,
366 std::vector<std::string>& statNames,
367 Ptr<const Comm<int> > comm,
368 const ECounterSetOp setOp=Intersection,
369 const std::string& filter="");
370
406 static void
407 computeGlobalTimerStatistics (stat_map_type& statData,
408 std::vector<std::string>& statNames,
409 const ECounterSetOp setOp=Intersection,
410 const std::string& filter="");
411
479 static void
480 summarize (Ptr<const Comm<int> > comm,
481 std::ostream &out=std::cout,
482 const bool alwaysWriteLocal=false,
483 const bool writeGlobalStats=true,
484 const bool writeZeroTimers=true,
485 const ECounterSetOp setOp=Intersection,
486 const std::string& filter="",
487 const bool ignoreZeroTimers=false);
488
506 static void
507 summarize (std::ostream& out=std::cout,
508 const bool alwaysWriteLocal=false,
509 const bool writeGlobalStats=true,
510 const bool writeZeroTimers=true,
511 const ECounterSetOp setOp=Intersection,
512 const std::string& filter="",
513 const bool ignoreZeroTimers=false);
514
596 static void
597 report (Ptr<const Comm<int> > comm,
598 std::ostream& out,
599 const std::string& filter,
600 const RCP<ParameterList>& params=null);
601
606 static void
607 report (Ptr<const Comm<int> > comm,
608 std::ostream& out,
609 const RCP<ParameterList>& params=null);
610
615 static void
616 report (std::ostream& out,
617 const std::string& filter,
618 const RCP<ParameterList>& params=null);
619
624 static void
625 report (std::ostream& out,
626 const RCP<ParameterList>& params=null);
627
629 static RCP<const ParameterList> getValidReportParameters ();
630
635 static void setStackedTimer(const Teuchos::RCP<Teuchos::StackedTimer>& t);
636
638 static Teuchos::RCP<Teuchos::StackedTimer> getStackedTimer();
639
640 private:
649
658
673 static void
674 summarizeToYaml (Ptr<const Comm<int> > comm,
675 std::ostream& out,
676 const ETimeMonitorYamlFormat yamlStyle,
677 const std::string& filter="");
678
683 static void
684 summarizeToYaml (std::ostream& out,
685 const ETimeMonitorYamlFormat yamlStyle,
686 const std::string& filter="");
687
692 static void setReportFormatParameter (ParameterList& plist);
693
698 static void setYamlFormatParameter (ParameterList& plist);
699
704 static void setSetOpParameter (ParameterList& plist);
705
720 static void setReportParameters (const RCP<ParameterList>& params);
721
723
724
729
734
738
741 static bool alwaysWriteLocal_;
742
748 static bool writeGlobalStats_;
749
751 static bool writeZeroTimers_;
753
758 static bool setParams_;
759
760protected:
764};
765
766
770 public TimeMonitor {
771public:
772
775
784 SyncTimeMonitor(Time& timer, Ptr<const Comm<int> > comm, bool reset=false);
785
787 SyncTimeMonitor () = delete;
788
790 ~SyncTimeMonitor() override;
792
793private:
794 // \brief Communicator on which barrier will be called.
796};
797
798
799} // namespace Teuchos
800
801
802namespace Teuchos {
803
813{
814 virtual void summarize (std::ostream& out) {
816 }
817};
818
869
870} // end namespace Teuchos
871
872
873namespace {
874
875// Inject the implementation in every translation unit.
876Teuchos::TimeMonitorSurrogateImplInserter timeMonitorSurrogateImplInserter;
877
878} // namespace (anonymous)
879
880#endif // TEUCHOS_TIMEMONITOR_H
Basic command line parser for input from (argc,argv[])
#define TEUCHOSCOMM_LIB_DLL_EXPORT
Templated Parameter List class.
Common capabilities for collecting and reporting performance data collectively across MPI processes.
Basic wall-clock timer class.
Abstract interface for distributed-memory communication.
Interface by which CommandLineProcessor may use TimeMonitor.
static RCP< TimeMonitorSurrogate > getTimeMonitorSurrogate()
static void setTimeMonitorSurrogate(const RCP< TimeMonitorSurrogate > &timeMonitorSurrogate)
A list of parameters of arbitrary type.
PerformanceMonitorBase(Time &counter_in, bool reset=false)
static RCP< Time > getNewCounter(const std::string &name)
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Smart reference counting pointer class for automatic garbage collection.
~SyncTimeMonitor() override
Destructor: stops the timer.
SyncTimeMonitor()=delete
Default constructor is deleted, since it would be unsafe.
Ptr< const Comm< int > > comm_
SyncTimeMonitor(Time &timer, Ptr< const Comm< int > > comm, bool reset=false)
Constructor: starts the timer.
Injects run-time dependency of a class on TimeMonitor.
TimeMonitorSurrogateImplInserter()
Constructor: inject dependency on TimeMonitor into CommandLineProcessor.
Implementation of TimeMonitorSurrogate that invokes TimeMonitor.
virtual void summarize(std::ostream &out)
Summarize timings over all process(es) to the given output stream.
ETimeMonitorReportFormat
Valid output formats for report().
ETimeMonitorYamlFormat
Valid YAML output formats for report().
static ETimeMonitorReportFormat reportFormat_
Parameters for the report() class method.
static bool writeZeroTimers_
Whether report() should report timers with zero call counts.
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.
static Teuchos::RCP< Teuchos::StackedTimer > stackedTimer_
Stacked timer for optional injection of timing from TimeMonitor-enabled objects.
static bool writeGlobalStats_
Whether report() should always compute global timer statistics.
static RCP< Time > getNewTimer(const std::string &name)
Return a new timer with the given name (class method).
static ECounterSetOp setOp_
Whether report() should use the intersection or union of timers over (MPI) processes.
static ETimeMonitorYamlFormat yamlStyle_
Current output style for report(), when using YAML output.
static bool alwaysWriteLocal_
Whether report() should always report (MPI) Process 0's local timer results.
TimeMonitor()=delete
Default constructor is deleted, since it would be unsafe.
TimeMonitor(Time &timer, bool reset=false)
Constructor: starts the timer.
static bool setParams_
Whether setReportParameters() completed successfully.
Wall-clock timer.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
ECounterSetOp
Set operation type for mergeCounterNames() to perform.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
std::map< std::string, std::vector< std::pair< double, double > > > stat_map_type
Global statistics collected from timer data.