Skip to content

Commit d348ff7

Browse files
committed
resolve comments
Signed-off-by: Martijn Govers <[email protected]>
1 parent 9ad7b8b commit d348ff7

File tree

9 files changed

+30
-33
lines changed

9 files changed

+30
-33
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/common/multi_threaded_logging.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#pragma once
66

7-
#include "logging_impl.hpp"
7+
#include "dummy_logging.hpp"
88

99
#include <mutex>
1010

power_grid_model_c/power_grid_model/include/power_grid_model/job_dispatch.hpp

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ class JobDispatch {
5959

6060
return BatchParameter{};
6161
}
62-
template <typename Adapter, typename ResultDataset, typename UpdateDataset>
63-
requires std::is_base_of_v<JobInterface<Adapter>, Adapter>
64-
static BatchParameter batch_calculation(Adapter& adapter, ResultDataset const& result_data,
65-
UpdateDataset const& update_data, Idx threading) {
66-
common::logging::NoMultiThreadedLogger no_log{};
67-
return batch_calculation(adapter, result_data, update_data, threading,
68-
static_cast<common::logging::MultiThreadedLogger&>(no_log));
69-
}
70-
template <typename Adapter, typename ResultDataset, typename UpdateDataset>
71-
requires std::is_base_of_v<JobInterface<Adapter>, Adapter>
72-
static BatchParameter batch_calculation(Adapter& adapter, ResultDataset const& result_data,
73-
UpdateDataset const& update_data) {
74-
return batch_calculation(adapter, result_data, update_data, sequential);
75-
}
7662

7763
// Lippincott pattern
7864
static auto scenario_exception_handler(std::vector<std::string>& messages) {
@@ -98,27 +84,27 @@ class JobDispatch {
9884
return [&base_adapter, &exceptions, &result_data, &update_data, &base_log](Idx start, Idx stride,
9985
Idx n_scenarios) {
10086
assert(n_scenarios <= narrow_cast<Idx>(exceptions.size()));
101-
auto thread_info_ptr = base_log.create_child();
102-
Logger& thread_info = *thread_info_ptr;
87+
auto thread_log_ptr = base_log.create_child();
88+
Logger& thread_log = *thread_log_ptr;
10389

104-
Timer t_total{thread_info, LogEvent::total_batch_calculation_in_thread};
90+
Timer t_total{thread_log, LogEvent::total_batch_calculation_in_thread};
10591

106-
auto const copy_adapter_functor = [&base_adapter, &thread_info]() {
107-
Timer const t_copy_adapter_functor{thread_info, LogEvent::copy_model};
92+
auto const copy_adapter_functor = [&base_adapter, &thread_log]() {
93+
Timer const t_copy_adapter_functor{thread_log, LogEvent::copy_model};
10894
auto result = Adapter{base_adapter};
109-
result.set_logger(thread_info);
95+
result.set_logger(thread_log);
11096
return result;
11197
};
11298

11399
auto adapter = copy_adapter_functor();
114100

115-
auto setup = [&adapter, &update_data, &thread_info](Idx scenario_idx) {
116-
Timer const t_update_model{thread_info, LogEvent::update_model};
101+
auto setup = [&adapter, &update_data, &thread_log](Idx scenario_idx) {
102+
Timer const t_update_model{thread_log, LogEvent::update_model};
117103
adapter.setup(update_data, scenario_idx);
118104
};
119105

120-
auto winddown = [&adapter, &thread_info]() {
121-
Timer const t_restore_model{thread_info, LogEvent::restore_model};
106+
auto winddown = [&adapter, &thread_log]() {
107+
Timer const t_restore_model{thread_log, LogEvent::restore_model};
122108
adapter.winddown();
123109
};
124110

@@ -135,7 +121,7 @@ class JobDispatch {
135121
std::move(recover_from_bad));
136122

137123
for (Idx scenario_idx = start; scenario_idx < n_scenarios; scenario_idx += stride) {
138-
Timer const t_total_single{thread_info, LogEvent::total_single_calculation_in_thread};
124+
Timer const t_total_single{thread_log, LogEvent::total_single_calculation_in_thread};
139125
calculate_scenario(scenario_idx);
140126
}
141127

power_grid_model_c/power_grid_model/include/power_grid_model/job_interface.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
// batch dispatch interface class
88

9-
#include "common/calculation_info.hpp"
109
#include "common/common.hpp"
10+
#include "common/logging.hpp"
1111

1212
#include <concepts>
1313
#include <type_traits>

power_grid_model_c/power_grid_model/include/power_grid_model/main_model.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "job_dispatch.hpp"
99
#include "main_model_impl.hpp"
1010

11+
#include "common/calculation_info.hpp"
12+
1113
#include <memory>
1214

1315
namespace power_grid_model {

power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
// common
1717
#include "common/common.hpp"
18+
#include "common/dummy_logging.hpp"
1819
#include "common/exception.hpp"
1920
#include "common/timer.hpp"
2021

tests/cpp_unit_tests/test_job_dispatch.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ class MultiThreadedTestLogger : public common::logging::MultiThreadedLoggerImpl<
156156

157157
Data const& report() const { return get().report(); }
158158
};
159+
160+
using common::logging::MultiThreadedLogger;
161+
162+
MultiThreadedLogger& no_logger() {
163+
static common::logging::NoMultiThreadedLogger instance;
164+
return instance;
165+
}
159166
} // namespace
160167

161168
TEST_CASE("Test job dispatch logic") {
@@ -166,13 +173,13 @@ TEST_CASE("Test job dispatch logic") {
166173
auto adapter = JobAdapterMock{counter};
167174
auto result_data = MockResultDataset{};
168175
auto const expected_result = BatchParameter{};
169-
auto const logger = MultiThreadedTestLogger{};
170176
SUBCASE("No update data") {
171177
bool const has_data = false;
172178
Idx const n_scenarios = 9; // arbitrary non-zero value
173179
auto const update_data = MockUpdateDataset(has_data, n_scenarios);
174180
adapter.reset_counters();
175-
auto const actual_result = JobDispatch::batch_calculation(adapter, result_data, update_data);
181+
auto const actual_result =
182+
JobDispatch::batch_calculation(adapter, result_data, update_data, JobDispatch::sequential, no_logger());
176183
CHECK(expected_result == actual_result);
177184
CHECK(adapter.get_calculate_counter() == 1);
178185
CHECK(adapter.get_cache_calculate_counter() == 0); // no cache calculation in this case
@@ -184,7 +191,8 @@ TEST_CASE("Test job dispatch logic") {
184191
Idx const n_scenarios = 0;
185192
auto const update_data = MockUpdateDataset(has_data, n_scenarios);
186193
adapter.reset_counters();
187-
auto const actual_result = JobDispatch::batch_calculation(adapter, result_data, update_data);
194+
auto const actual_result =
195+
JobDispatch::batch_calculation(adapter, result_data, update_data, JobDispatch::sequential, no_logger());
188196
CHECK(expected_result == actual_result);
189197
// no calculations should be done
190198
CHECK(adapter.get_calculate_counter() == 0);
@@ -198,7 +206,7 @@ TEST_CASE("Test job dispatch logic") {
198206
auto const update_data = MockUpdateDataset(has_data, n_scenarios);
199207
adapter.reset_counters();
200208
auto const actual_result =
201-
JobDispatch::batch_calculation(adapter, result_data, update_data, JobDispatch::sequential);
209+
JobDispatch::batch_calculation(adapter, result_data, update_data, JobDispatch::sequential, no_logger());
202210
CHECK(expected_result == actual_result);
203211
// n_scenarios calculations should be done as we run sequentially
204212
CHECK(adapter.get_calculate_counter() == n_scenarios);

tests/cpp_unit_tests/test_math_solver_pf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "test_math_solver_common.hpp"
1010

11-
#include <power_grid_model/common/logging_impl.hpp>
11+
#include <power_grid_model/common/dummy_logging.hpp>
1212
#include <power_grid_model/math_solver/sparse_lu_solver.hpp>
1313
#include <power_grid_model/math_solver/y_bus.hpp>
1414

tests/cpp_unit_tests/test_math_solver_se.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "test_math_solver_common.hpp"
1010

11+
#include <power_grid_model/common/dummy_logging.hpp>
1112
#include <power_grid_model/common/exception.hpp>
12-
#include <power_grid_model/common/logging_impl.hpp>
1313
#include <power_grid_model/math_solver/sparse_lu_solver.hpp>
1414
#include <power_grid_model/math_solver/y_bus.hpp>
1515

0 commit comments

Comments
 (0)