Wildmeshing Toolkit
Scheduler.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <spdlog/common.h>
5 
6 namespace wmtk {
7 
9 {
10 public:
17 
23  int64_t number_of_failed_operations() const { return m_num_op_fail; }
24 
31 
32  inline double total_time() const { return collecting_time + sorting_time + executing_time; }
33 
34  inline void succeed() { ++m_num_op_success; }
35  inline void fail() { ++m_num_op_fail; }
36 
37  inline void operator+=(const SchedulerStats& s)
38  {
41 
45  }
46 
47 
48  double collecting_time = 0;
49  double sorting_time = 0;
50  double executing_time = 0;
51 
52  std::vector<SchedulerStats> sub_stats;
53 
54  double avg_sub_collecting_time() const
55  {
56  double res = 0;
57  for (const auto& s : sub_stats) {
58  res += s.collecting_time;
59  }
60  return res / sub_stats.size();
61  }
62 
63  double avg_sub_sorting_time() const
64  {
65  double res = 0;
66  for (const auto& s : sub_stats) {
67  res += s.sorting_time;
68  }
69  return res / sub_stats.size();
70  }
71 
72  double avg_sub_executing_time() const
73  {
74  double res = 0;
75  for (const auto& s : sub_stats) {
76  res += s.executing_time;
77  }
78  return res / sub_stats.size();
79  }
80 
81  // private:
82  int64_t m_num_op_success = 0;
83  int64_t m_num_op_fail = 0;
84 
85  void print_update_log(size_t total, spdlog::level::level_enum = spdlog::level::info) const;
86 };
87 
88 class Scheduler
89 {
90 public:
93 
97  const TypedAttributeHandle<char>& flag_handle);
100  const TypedAttributeHandle<int64_t>& color_handle);
101 
102  const SchedulerStats& stats() const { return m_stats; }
103 
104  void set_update_frequency(std::optional<size_t>&& freq = {});
105 
106 private:
108  std::optional<size_t> m_update_frequency = {};
109 
110  void log(const size_t total);
111  void log(const SchedulerStats& stats, const size_t total);
112 };
113 
114 } // namespace wmtk
void log(const size_t total)
Definition: Scheduler.cpp:377
SchedulerStats run_operation_on_all(operations::Operation &op)
Definition: Scheduler.cpp:33
SchedulerStats run_operation_on_all_coloring(operations::Operation &op, const TypedAttributeHandle< int64_t > &color_handle)
Definition: Scheduler.cpp:242
void set_update_frequency(std::optional< size_t > &&freq={})
Definition: Scheduler.cpp:393
const SchedulerStats & stats() const
Definition: Scheduler.hpp:102
SchedulerStats m_stats
Definition: Scheduler.hpp:107
std::optional< size_t > m_update_frequency
Definition: Scheduler.hpp:108
double total_time() const
Definition: Scheduler.hpp:32
std::vector< SchedulerStats > sub_stats
Definition: Scheduler.hpp:52
double avg_sub_collecting_time() const
Definition: Scheduler.hpp:54
double avg_sub_executing_time() const
Definition: Scheduler.hpp:72
int64_t number_of_failed_operations() const
Returns the number of failed operations performed by the scheduler.
Definition: Scheduler.hpp:23
void operator+=(const SchedulerStats &s)
Definition: Scheduler.hpp:37
int64_t m_num_op_success
Definition: Scheduler.hpp:82
int64_t number_of_performed_operations() const
Returns the number of performed operations performed by the scheduler.
Definition: Scheduler.hpp:30
double avg_sub_sorting_time() const
Definition: Scheduler.hpp:63
int64_t number_of_successful_operations() const
Returns the number of successful operations performed by the scheduler.
Definition: Scheduler.hpp:16
void print_update_log(size_t total, spdlog::level::level_enum=spdlog::level::info) const
Definition: Scheduler.cpp:399
Handle that represents attributes for some mesh.
Definition: Accessor.hpp:6