Skip to content

Commit 5e7b49b

Browse files
committed
Add timing measurements for general procedures like io
1 parent e266e03 commit 5e7b49b

5 files changed

Lines changed: 64 additions & 0 deletions

File tree

mt-kahypar/dynamic/dynamic_io.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,26 @@ inline std::vector<HypernodeID> parseIDs(const std::string& line) {
262262

263263
file.close();
264264
}
265+
266+
inline void generateOtherTimingsFile(Context& context)
267+
{
268+
context.dynamic.result_folder += "_other_timings/";
269+
generateFileName(context);
270+
std::string filename = context.dynamic.output_path;
271+
std::ofstream file(filename);
272+
if (!file.is_open()) {
273+
throw std::runtime_error("Could not open file: " + filename);
274+
}
275+
std::cout << "Saving other timings to file: " << filename << std::endl;
276+
file << "total_time, strategy_time, setup_time, initial_partitioning_time, io_time_change_parsing, io_time_graph_parsing" << std::endl;
277+
file << std::chrono::duration_cast<std::chrono::milliseconds>(context.dynamic.other_timings.total_time).count() << ", "
278+
<< std::chrono::duration_cast<std::chrono::milliseconds>(context.dynamic.other_timings.strategy_time).count() << ", "
279+
<< std::chrono::duration_cast<std::chrono::milliseconds>(context.dynamic.other_timings.setup_time).count() << ", "
280+
<< std::chrono::duration_cast<std::chrono::milliseconds>(context.dynamic.other_timings.initial_partitioning_time).count() << ", "
281+
<< std::chrono::duration_cast<std::chrono::milliseconds>(context.dynamic.other_timings.io_time_change_parsing).count() << ", "
282+
<< std::chrono::duration_cast<std::chrono::milliseconds>(context.dynamic.other_timings.io_time_graph_parsing).count()
283+
<< std::endl;
284+
file.close();
285+
286+
}
265287
}

mt-kahypar/dynamic/dynamic_partitioner.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,25 @@
1313
namespace mt_kahypar::dyn {
1414
inline int partition(Context& context) {
1515

16+
context.dynamic.other_timings = OtherTimings();
17+
auto total_time_start = std::chrono::high_resolution_clock::now();
18+
1619

1720
context.partition.instance_type = InstanceType::hypergraph;
1821
context.partition.objective = Objective::km1;
1922
context.partition.gain_policy = GainPolicy::km1;
2023

2124
// Read Hypergraph
25+
auto graph_time_parsing_start = std::chrono::high_resolution_clock::now();
2226
mt_kahypar_hypergraph_t hypergraph_t = io::readInputFile(
2327
context.partition.graph_filename, context.partition.preset_type,
2428
context.partition.instance_type, context.partition.file_format,
2529
context.preprocessing.stable_construction_of_incident_edges);
2630
auto& hypergraph_m = utils::cast<ds::MutableHypergraph>(hypergraph_t);
31+
context.dynamic.other_timings.io_time_graph_parsing = std::chrono::high_resolution_clock::now() -
32+
graph_time_parsing_start;
33+
34+
auto setup_time_start = std::chrono::high_resolution_clock::now();
2735

2836
// Initialize Memory Pool and Algorithm/Policy Registries
2937
register_memory_pool(hypergraph_t, context);
@@ -75,6 +83,8 @@ namespace mt_kahypar::dyn {
7583
LocalFMRound localFM_round = LocalFMRound();
7684
context.dynamic.local_fm_round = &localFM_round;
7785

86+
context.dynamic.other_timings.setup_time = std::chrono::high_resolution_clock::now() - setup_time_start;
87+
7888
try {
7989

8090
std::cout << "Processing " << num_changes << " changes" << std::endl;
@@ -86,14 +96,17 @@ namespace mt_kahypar::dyn {
8696
size_t log_step_size = num_changes * context.dynamic.logging_step_size_pct;
8797

8898
auto duration_sum = std::chrono::high_resolution_clock::duration::zero();
99+
auto change_io_duration_sum = std::chrono::high_resolution_clock::duration::zero();
89100

90101
for (size_t i = 0; i < num_changes; ++i) {
102+
HighResClockTimepoint start_io = std::chrono::high_resolution_clock::now();
91103
Change change;
92104
if (!context.dynamic.stream_changes) {
93105
change = changes[i];
94106
} else {
95107
change = parseChange(changes_file);
96108
}
109+
change_io_duration_sum += std::chrono::high_resolution_clock::now() - start_io;
97110
HighResClockTimepoint start = std::chrono::high_resolution_clock::now();
98111
strategy->partition(change, num_changes);
99112
auto duration = std::chrono::high_resolution_clock::now() - start;
@@ -104,6 +117,9 @@ namespace mt_kahypar::dyn {
104117
log_km1_live(i+1, num_changes, context, DynamicStrategy::getPartitionedHypergraphCopy(*strategy), duration_sum);
105118
}
106119

120+
context.dynamic.other_timings.strategy_time = duration_sum;
121+
context.dynamic.other_timings.io_time_change_parsing = change_io_duration_sum;
122+
107123
strategy->printAdditionalFinalStats();
108124

109125
if (context.partition.write_partition_file) {
@@ -119,6 +135,10 @@ namespace mt_kahypar::dyn {
119135
exit(1);
120136
}
121137

138+
context.dynamic.other_timings.total_time = std::chrono::high_resolution_clock::now() - total_time_start;
139+
if (context.dynamic.save_other_timings) {
140+
generateOtherTimingsFile(context);
141+
}
122142
return 0;
123143
}
124144
}

mt-kahypar/dynamic/dynamic_strategy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ namespace mt_kahypar::dyn {
108108
static ds::PartitionedHypergraph<ds::MutableHypergraph>
109109
partition_hypergraph_km1(ds::MutableHypergraph &hypergraph, Context &context) {
110110

111+
auto init_hgr_partitioning_start = std::chrono::high_resolution_clock::now();
112+
111113
// copy the hypergraph to make sure we don't modify the original
112114
// ds::MutableHypergraph hypergraph_copy = hypergraph.copy();
113115

@@ -131,6 +133,8 @@ namespace mt_kahypar::dyn {
131133

132134
partitioned_hypergraph_s.setHypergraph(hypergraph);
133135

136+
context.dynamic.other_timings.initial_partitioning_time = std::chrono::high_resolution_clock::now() - init_hgr_partitioning_start;
137+
134138
return partitioned_hypergraph_s;
135139
}
136140

mt-kahypar/io/command_line_options.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,10 @@ namespace mt_kahypar {
903903
("d-changing-total-weight",
904904
po::value<bool>(&context.dynamic.changing_total_weight)->value_name("<bool>"),
905905
"Whether the total weight of the graph is expected to change, used for vcycle spacing");
906+
dynamic_options.add_options()
907+
("d-save-other-timings",
908+
po::value<bool>(&context.dynamic.save_other_timings)->default_value(false),
909+
"If true, then the partitioner saves the timings of other parts of the algorithm, such as io and initial partitioning");
906910
return dynamic_options;
907911
}
908912

mt-kahypar/partition/context.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ struct LocalFMRound {
299299
std::vector<Move> moves;
300300
};
301301

302+
struct OtherTimings
303+
{
304+
std::chrono::high_resolution_clock::duration total_time;
305+
std::chrono::high_resolution_clock::duration strategy_time;
306+
std::chrono::high_resolution_clock::duration setup_time;
307+
std::chrono::high_resolution_clock::duration initial_partitioning_time;
308+
std::chrono::high_resolution_clock::duration io_time_change_parsing;
309+
std::chrono::high_resolution_clock::duration io_time_graph_parsing;
310+
};
311+
302312
struct DynamicParameters {
303313
std::string vcycle_algorithm = "kway_fm";
304314
size_t vcycle_num = 1;
@@ -333,6 +343,10 @@ struct DynamicParameters {
333343
HyperedgeWeight incremental_km1 = 0;
334344
LocalFMRound* local_fm_round = nullptr;
335345

346+
// other timings independent of strategy used
347+
OtherTimings other_timings;
348+
bool save_other_timings = false;
349+
336350
// statistics
337351
std::int64_t km1_gain_vcycle = 0;
338352
std::chrono::high_resolution_clock::duration vcycle_duration_sum = std::chrono::high_resolution_clock::duration::zero();

0 commit comments

Comments
 (0)