Skip to content

Commit 99bcbab

Browse files
committed
pre- and postprocessing for evo, benchmark bash scripts adjusted
1 parent f7b6845 commit 99bcbab

6 files changed

Lines changed: 119 additions & 21 deletions

File tree

benchmark.sh

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,55 @@
11
#!/bin/bash
22

3-
# Check if argument is provided
4-
if [ -z "$1" ] || [ -z "$2" ]; then
5-
echo "Usage: $0 n [runs] t [seconds per run]"
3+
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]; then
4+
echo "Usage: $0 time_limit [seconds] seed_num [number of seeds] mode [evo || multilevel] time_step [time step limit for evo]"
65
exit 1
76
fi
87

98
# help command
109
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
11-
echo "Usage: $0 n [runs] t [seconds per run]"
10+
echo "Usage: $0 time_limit [seconds] seed_num [number of seeds] mode [evo || multilevel]"
1211
exit 0
1312
fi
1413

15-
echo "timestamp, km1" > output.csv
14+
TIME_LIMIT="$1"
15+
SEED_NUM="$2"
16+
MODE="$3"
17+
TIME_STEP="$4"
1618

1719

18-
for i in $(seq 1 "$1"); do
19-
echo "Second: $i"
20-
timeout "$2" ./infinite-run.sh
21-
if [ "$i" -lt "$1" ]; then
22-
echo "###" >> output.csv
23-
fi
24-
done
20+
if [ "$MODE" == "multilevel" ]; then
21+
echo "timestamp, mode, km1" > output.csv
22+
23+
# loop for every seed
24+
for i in $(seq 1 "$SEED_NUM"); do
25+
START_TIMESTAMP=$(date +"%T.%N")
26+
echo "$START_TIMESTAMP" >> output.csv
27+
# echo "Running iteration $i with seed $i (${TIME_LIMIT}s timeout)"
28+
timeout "$TIME_LIMIT" ./infinite-run.sh "$MODE" "$i"
29+
if [ "$i" -lt "$SEED_NUM" ]; then
30+
echo "###" >> output.csv
31+
fi
32+
done
33+
elif [ "$MODE" == "evo" ]; then
34+
echo "timestamp, mode, km1" > output_evo.csv
35+
36+
# loop for every seed
37+
for i in $(seq 1 "$SEED_NUM"); do
38+
echo "Running seed $i"
39+
START_TIMESTAMP=$(date +"%T.%N")
40+
echo "$START_TIMESTAMP" >> output_evo.csv
41+
# loop for every time step multiple
42+
for j in $(seq 1 "$((TIME_LIMIT / TIME_STEP))"); do
43+
current_time_limit=$((j * TIME_STEP))
44+
echo "Running iteration $i with seed $i (${current_time_limit}s timeout)"
45+
./infinite-run.sh "$MODE" "$i" "$current_time_limit"
46+
done
47+
if [ "$i" -lt "$SEED_NUM" ]; then
48+
echo "###" >> output_evo.csv
49+
fi
50+
done
51+
52+
else
53+
echo "Invalid mode: $MODE"
54+
exit 1
55+
fi

infinite-run.sh

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
#!/bin/bash
22

3-
while true; do
3+
EXEC="./build/mt-kahypar/application/MtKaHyPar.exe"
4+
INSTANCE="./tests/instances/ibm01.hgr"
5+
6+
COMMON_ARGS="-h ${INSTANCE} -k 8 -e 0.03 -t 10 -m direct -okm1 --seed=${2:-1}"
7+
8+
extract_km1() {
9+
# extracts the km1 value
10+
grep -E '^.*km1\s+= [0-9]+ \(primary objective function\)' | awk '{print $3;}'
11+
}
12+
13+
multilevel_run() {
14+
15+
while true; do
16+
# Normal Multilevel (no evo)
17+
BASELINE_OUT="$(${EXEC} ${COMMON_ARGS} --preset-type=default 2>/dev/null | extract_km1)"
18+
TIMESTAMP=$(date +"%T.%N")
19+
echo "$TIMESTAMP, baseline, $BASELINE_OUT" >> output.csv
20+
done
21+
}
22+
23+
evolutionary_run() {
24+
# Evolutionary enabled
25+
EVO_OUT="$(${EXEC} ${COMMON_ARGS} --preset-type=default --partition-evolutionary=true --time-limit=$1 2>/dev/null | extract_km1)"
426
TIMESTAMP=$(date +"%T.%N")
5-
OUTPUT="$(./build/mt-kahypar/application/MtKaHyPar.exe -h ./tests/instances/ibm01.hgr --preset-type=default -k 8 -e 0.03 -t 10 -m direct -okm1 --seed=1 | grep -E '^.*km1\s+= [0-9]+ \(primary objective function\)' | awk '{print $3;}')"
6-
echo "$TIMESTAMP, $OUTPUT" >> output.csv
7-
done
27+
echo "$TIMESTAMP, evolutionary, $EVO_OUT" >> output_evo.csv
28+
}
29+
30+
## MAIN
31+
if [ -z "$1" ]; then
32+
echo "Usage: $0 mode"
33+
echo "mode: multilevel | evolutionary"
34+
exit 1
35+
fi
36+
37+
if [ "$1" == "multilevel" ]; then
38+
multilevel_run
39+
elif [ "$1" == "evo" ]; then
40+
evolutionary_run "$3"
41+
else
42+
echo "Invalid mode: $1"
43+
exit 1
44+
fi

mt-kahypar/partition/evo_partitioner.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ namespace mt_kahypar {
4545
timer.start_timer("preprocessing", "Preprocessing");
4646
DegreeZeroHypernodeRemover<TypeTraits> degree_zero_hn_remover(context);
4747
LargeHyperedgeRemover<TypeTraits> large_he_remover(context);
48-
preprocess(hypergraph, context, target_graph);
49-
//sanitize(hypergraph, context, degree_zero_hn_remover, large_he_remover);
48+
Partitioner<TypeTraits>::preprocess(hypergraph, context, target_graph);
49+
EvoPartitioner<TypeTraits>::sanitize(hypergraph, context, degree_zero_hn_remover, large_he_remover);
5050
timer.stop_timer("preprocessing");
5151

5252
// ################## EVOLUTIONARY PARTITIONING ##################
@@ -96,6 +96,7 @@ namespace mt_kahypar {
9696
timer.start_timer("postprocessing", "Postprocessing");
9797
large_he_remover.restoreLargeHyperedges(final_partition);
9898
degree_zero_hn_remover.restoreDegreeZeroHypernodes(final_partition);
99+
//forceFixedVertexAssignment(partitioned_hypergraph, context);
99100
timer.stop_timer("postprocessing");
100101

101102
#ifdef KAHYPAR_ENABLE_STEINER_TREE_METRIC
@@ -104,7 +105,7 @@ namespace mt_kahypar {
104105
context.partition.objective = Objective::steiner_tree;
105106
timer.start_timer("one_to_one_mapping", "One-To-One Mapping");
106107
InitialMapping<TypeTraits>::mapToTargetGraph(
107-
final_partition, *target_graph, context);
108+
final_partition, *target_graph, context);
108109
timer.stop_timer("one_to_one_mapping");
109110
}
110111
#endif
@@ -151,6 +152,7 @@ namespace mt_kahypar {
151152
LOG << "DEBUG: Initial population target size =" << context.evolutionary.population_size;
152153
int best = std::numeric_limits<HyperedgeWeight>::max();
153154
int iteration = 0;
155+
154156
while (population.size() < context.evolutionary.population_size &&
155157
time_elapsed <= duration) {
156158
LOG << "DEBUG: Initial pop loop - Iteration" << iteration << ", Pop size:" << population.size();
@@ -463,8 +465,6 @@ namespace mt_kahypar {
463465
context.evolutionary.iteration += total_iterations.load();
464466
context.partition.verbose_output = true;
465467
LOG << "Performed " << total_iterations.load() << " Evolutionary Iterations" << "\n";
466-
LOG << " " << (total_iterations.load() - total_mutations.load() - total_combinations.load())
467-
<< " Initial Population members" << "\n";
468468
LOG << " " << total_mutations.load() << " Mutations" << "\n";
469469
LOG << " " << total_combinations.load() << " Combinations" << "\n";
470470

mt-kahypar/partition/partitioner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,5 +483,14 @@ namespace mt_kahypar {
483483
::mt_kahypar::preprocess(hypergraph, context, target_graph);
484484
}
485485

486+
template<typename TypeTraits>
487+
void Partitioner<TypeTraits>::sanitize(
488+
Hypergraph& hypergraph,
489+
Context& context,
490+
DegreeZeroHypernodeRemover<TypeTraits>& degree_zero_hn_remover,
491+
LargeHyperedgeRemover<TypeTraits>& large_he_remover) {
492+
::mt_kahypar::sanitize<TypeTraits>(hypergraph, context, degree_zero_hn_remover, large_he_remover);
493+
}
494+
486495
INSTANTIATE_CLASS_WITH_TYPE_TRAITS(Partitioner)
487496
}

mt-kahypar/partition/partitioner.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#pragma once
2929

3030
#include "mt-kahypar/partition/context.h"
31+
#include "mt-kahypar/partition/preprocessing/sparsification/degree_zero_hn_remover.h"
32+
#include "mt-kahypar/partition/preprocessing/sparsification/large_he_remover.h"
3133

3234
namespace mt_kahypar {
3335

@@ -53,6 +55,11 @@ class Partitioner {
5355
static void configurePreprocessing(const Hypergraph& hypergraph, Context& context);
5456
static void setupContext(Hypergraph& hypergraph, Context& context, TargetGraph* target_graph);
5557
static void preprocess(Hypergraph& hypergraph, Context& context, TargetGraph* target_graph);
58+
static void sanitize(
59+
Hypergraph& hypergraph,
60+
Context& context,
61+
DegreeZeroHypernodeRemover<TypeTraits>& degree_zero_hn_remover,
62+
LargeHyperedgeRemover<TypeTraits>& large_he_remover);
5663

5764
};
5865

output_evo.csv

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
timestamp, mode, km1
2+
00:58:34.465105200
3+
00:58:35.765034000, evolutionary, 864
4+
00:58:38.056055500, evolutionary, 876
5+
00:58:41.341020400, evolutionary, 853
6+
00:58:45.680355200, evolutionary, 865
7+
00:58:50.994805100, evolutionary, 865
8+
###
9+
00:58:51.012464400
10+
00:58:52.342458000, evolutionary, 875
11+
00:58:54.589272700, evolutionary, 867
12+
00:58:57.879431300, evolutionary, 874
13+
00:59:02.214291500, evolutionary, 853
14+
00:59:07.499670900, evolutionary, 861

0 commit comments

Comments
 (0)