18#include "vipra/util/clock.hpp"
19#include "vipra/util/mpi_util.hpp"
21namespace VIPRA::Util {
24 using time_t = Util::nano;
26 void start_new() { _clock.start(); }
27 void pause() { _clock.pause(); }
28 void resume() { _clock.resume(); }
29 void stop() { _times.emplace_back(_clock.stop()); }
31 static void set_output_file(std::filesystem::path
const& filepath)
33 timingPath = filepath;
41 std::vector<int64_t> timings(_times.size());
43 _times.begin(), _times.end(), timings.begin(),
44 [](Util::nano
const& time) { return static_cast<int64_t>(time.count()); });
46 auto [allTimings, counts] = Util::mpi_gather_all_vectors<int64_t>(timings);
48 Util::master_do([&]() { output_timings_file(allTimings, counts, timingPath); });
50 MPI_Barrier(MPI_COMM_WORLD);
53 void output_timings_file(std::vector<int64_t>
const& timings,
54 std::vector<int>
const& counts,
55 std::filesystem::path
const& filepath)
57 std::ofstream file(filepath, std::ios_base::app);
59 if ( ! file.is_open() )
60 throw std::runtime_error(
"Unable to open timings output file: " +
65 for (
int i = 0; i < counts.size(); ++i ) {
66 file << _name << i <<
',';
68 for (
int j = 0; j < counts[i]; ++j ) {
69 file << time_string(static_cast<time_t>(timings[start + j]));
70 if ( j != counts[i] - 1 ) file <<
',';
82 std::ofstream file(timingPath, std::ios_base::app);
84 if ( ! file.is_open() )
85 throw std::runtime_error(
"Unable to open timings output file: " +
90 for (
size_t timeIdx = 0; timeIdx < _times.size(); ++timeIdx ) {
91 file << time_string(static_cast<time_t>(_times[timeIdx]));
92 if ( timeIdx != _times.size() - 1 ) file <<
',';
101 ~Timings() =
default;
102 Timings(Timings&&) =
default;
103 auto operator=(
const Timings&) -> Timings& =
default;
104 auto operator=(Timings&&) -> Timings& =
default;
105 Timings(Timings
const&) =
default;
106 explicit Timings(
char const* name) : _name(name) {}
110 Util::Clock<time_t> _clock;
111 std::vector<time_t> _times;
113 static std::filesystem::path timingPath;
121namespace VIPRA::Util {
124 explicit Timings(
char const* )
noexcept {}
125 void start_new()
const noexcept {}
126 void pause()
const noexcept {}
127 void resume()
const noexcept {}
128 void stop()
const noexcept {}
129 void output_timings()
const noexcept {}
130 void output_timings(std::filesystem::path
const& )
const noexcept {}
131 static void set_output_file(std::filesystem::path
const& )
noexcept {}
Definition timing.hpp:122