ThunderEgg  1.0.0
Timer.h
Go to the documentation of this file.
1 /***************************************************************************
2  * ThunderEgg, a library for solvers on adaptively refined block-structured
3  * Cartesian grids.
4  *
5  * Copyright (c) 2017-2021 Scott Aiton
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  ***************************************************************************/
20 
21 #ifndef THUNDEREGG_TIMER_H
22 #define THUNDEREGG_TIMER_H
23 
31 #include <ThunderEgg/tpl/json.hpp>
32 #include <list>
33 #include <map>
34 #include <ostream>
35 #include <string>
36 namespace ThunderEgg {
60 class Timer
61 {
62 private:
66  Communicator comm;
70  class Timing;
74  std::unique_ptr<Timing> root;
79  std::list<std::reference_wrapper<Timing>> stack;
80  std::map<int, tpl::nlohmann::json> domains;
81 
82 public:
86  explicit Timer(const Communicator& comm);
90  ~Timer();
96  void start(const std::string& name);
104  void stop(const std::string& name);
112  void addDomain(int domain_id, tpl::nlohmann::json domain);
120  void startDomainTiming(int domain_id, const std::string& name);
130  void stopDomainTiming(int domain_id, const std::string& name);
139  void startPatchTiming(int patch_id, int domain_id, const std::string& name);
150  void stopPatchTiming(int patch_id, int domain_id, const std::string& name);
163  void addIntInfo(const std::string& name, int info);
176  void addDoubleInfo(const std::string& name, double info);
185  friend std::ostream& operator<<(std::ostream& os, const Timer& timer);
193  friend void to_json(tpl::nlohmann::json& j, const Timer& timer);
201  void saveToFile(const std::string& filename) const;
202 };
203 } // namespace ThunderEgg
204 #endif
RuntimeError.h
RuntimeError struct.
ThunderEgg::Timer::Timer
Timer(const Communicator &comm)
Construct a new empty Timer object.
ThunderEgg::Timer::~Timer
~Timer()
Destruct a Timer object.
ThunderEgg::Timer::addDoubleInfo
void addDoubleInfo(const std::string &name, double info)
Add information to a timing.
ThunderEgg
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
ThunderEgg::Timer::addDomain
void addDomain(int domain_id, tpl::nlohmann::json domain)
add a domain to to timer
ThunderEgg::Timer::to_json
friend void to_json(tpl::nlohmann::json &j, const Timer &timer)
Convert a timer to a json serialization, this is collective over all processes will only result in a ...
ThunderEgg::Timer::start
void start(const std::string &name)
Start a new timing.
ThunderEgg::Timer::stop
void stop(const std::string &name)
Stop a timing.
ThunderEgg::Timer::startPatchTiming
void startPatchTiming(int patch_id, int domain_id, const std::string &name)
Start a new Domain associated timing.
ThunderEgg::Timer::stopDomainTiming
void stopDomainTiming(int domain_id, const std::string &name)
Stop a Domain associated timing.
ThunderEgg::Timer::startDomainTiming
void startDomainTiming(int domain_id, const std::string &name)
Start a new Domain associated timing.
ThunderEgg::Timer
Class for keeping track of parallel timings.
Definition: Timer.h:60
ThunderEgg::Communicator
wrapper arount MPI_Comm, provides proper copy operators. Classes that have a communicator are meant t...
Definition: Communicator.h:36
Communicator.h
Communicator class.
ThunderEgg::Timer::stopPatchTiming
void stopPatchTiming(int patch_id, int domain_id, const std::string &name)
Stop a Domain associated timing.
ThunderEgg::Timer::operator<<
friend std::ostream & operator<<(std::ostream &os, const Timer &timer)
ostream operator for Timer, this is collective for all ranks, will only output on rank 0
ThunderEgg::Timer::addIntInfo
void addIntInfo(const std::string &name, int info)
Add information to a timing.
ThunderEgg::Timer::saveToFile
void saveToFile(const std::string &filename) const
Save a json representation of the timer to the file. This is collective over all processes.