Skip to content

Commit a5b17c8

Browse files
committed
fix parallel runner
1 parent dfb9724 commit a5b17c8

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

multithread/parallel_runner.hpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ template <ISolver Solver> class ParallelRunner {
2323
int num_threads_;
2424
std::vector<Solver> instances;
2525
std::vector<std::optional<typename Solver::Ret>> rets;
26+
int num_failures_;
2627

2728
std::mutex mtx;
2829

2930
ParallelRunner(int num_threads = std::thread::hardware_concurrency())
30-
: num_threads_(num_threads > 0 ? num_threads : 1) {
31+
: num_threads_(num_threads > 0 ? num_threads : 1), num_failures_(0) {
3132
std::cerr << "num_threads: " << num_threads_ << std::endl;
3233
}
3334

@@ -40,6 +41,10 @@ template <ISolver Solver> class ParallelRunner {
4041
}
4142
}
4243

44+
void show_result() const {
45+
std::cerr << "Done: " << num_failures_ << " failures." << std::endl;
46+
}
47+
4348
void run_sequential() {
4449
rets.assign(instances.size(), std::nullopt);
4550

@@ -49,6 +54,8 @@ template <ISolver Solver> class ParallelRunner {
4954
mhc_stdout_(instances.at(index), rets.at(index).value(), index);
5055
}
5156
}
57+
58+
show_result();
5259
}
5360

5461
void run_parallel(int num_skip = 0) {
@@ -85,6 +92,8 @@ template <ISolver Solver> class ParallelRunner {
8592
}
8693

8794
for (auto &f : futures) f.get();
95+
96+
show_result();
8897
}
8998

9099
void run_single_(int current_index) {
@@ -100,10 +109,12 @@ template <ISolver Solver> class ParallelRunner {
100109
} catch (const std::exception &e) {
101110
std::unique_lock<std::mutex> lock(mtx);
102111
std::cerr << "Error in Case #" << current_index + 1 << ": " << e.what() << std::endl;
112+
++num_failures_;
103113
return;
104114
} catch (...) {
105115
std::unique_lock<std::mutex> lock(mtx);
106116
std::cerr << "Unknown error in Case #" << current_index + 1 << std::endl;
117+
++num_failures_;
107118
return;
108119
}
109120

@@ -122,7 +133,6 @@ template <ISolver Solver> class ParallelRunner {
122133
std::cout << std::flush;
123134
}
124135
};
125-
126136
#endif // PARALLEL_RUNNER_HPP
127137

128138
/* Usage:
@@ -143,10 +153,12 @@ struct Solver {
143153
}
144154
};
145155
146-
int T;
147-
cin >> T;
156+
int main() {
157+
int T;
158+
cin >> T;
148159
149-
ParallelRunner<Solver> pm;
150-
pm.read_all(T);
151-
pm.run_parallel();
160+
ParallelRunner<Solver> pm;
161+
pm.read_all(T);
162+
pm.run_parallel();
163+
}
152164
*/

0 commit comments

Comments
 (0)