OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
timer.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
37#ifndef PFC_MPI_TIMER_HPP
38#define PFC_MPI_TIMER_HPP
39
40#include <iostream>
41#include <mpi.h>
42#include <string>
43
44namespace pfc {
45namespace mpi {
46
47class timer {
48 double tic_;
49 double toc_;
50 double duration_ = 0.0;
51 std::string description_;
52
53public:
54 void tic();
55 double toc();
56 double duration() const;
57 void reset();
58 void description(const std::string &);
59 std::string description() const;
60 friend std::ostream &operator<<(std::ostream &os, const timer &t);
61};
62
63inline void timer::reset() { duration_ = 0.0; }
64
65inline std::string timer::description() const { return description_; }
66
67inline void timer::description(const std::string &description) {
68 description_ = description;
69}
70
71inline std::ostream &operator<<(std::ostream &os, const timer &t) {
72 os << t.description();
73 return os;
74}
75
76inline void timer::tic() { tic_ = MPI_Wtime(); }
77
78inline double timer::toc() {
79 toc_ = MPI_Wtime();
80 duration_ += toc_ - tic_;
81 return toc_ - tic_;
82}
83
84} // namespace mpi
85} // namespace pfc
86
87#endif // PFC_MPI_TIMER_HPP
Definition timer.hpp:47
Represents the global simulation domain (the "world").
Definition world.hpp:91