Skip to content

Commit bd29c0b

Browse files
Merge branch 'master' into more_ILPs_from_old_branch
2 parents 5da3798 + 5c3a2a2 commit bd29c0b

File tree

144 files changed

+6748
-1390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+6748
-1390
lines changed

CMakeLists.txt

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,62 @@ add_subdirectory(.githooks)
3131
# --- Compile Options Configuration ---
3232
# Common compile options including strict warnings and error-on-warning
3333
set(COMMON_CXX_WARNING_FLAGS
34-
"-Wall"
35-
"-Wextra"
3634
"-Wfatal-errors"
3735
"-Wconversion"
3836
"-Wsign-conversion"
39-
"-Wunused"
4037
"-Wunreachable-code"
4138
"-Wuninitialized"
39+
"-pedantic"
40+
"-Wpedantic"
41+
"-Wold-style-cast"
42+
"-Wcast-align"
4243
"-Werror"
44+
"-Wall"
45+
"-Wextra"
46+
"-Wundef"
47+
"-Wunused"
48+
"-Wcast-qual"
49+
"-Wpointer-arith"
50+
"-Wdate-time"
51+
"-Wfloat-equal"
52+
"-Wformat=2"
53+
"-Wshadow"
54+
"-Wsign-compare"
55+
"-Wunused-macros"
56+
"-Wvla"
57+
"-Wdisabled-optimization"
58+
"-Wempty-body"
59+
"-Wignored-qualifiers"
60+
"-Wtype-limits"
61+
"-Wshift-negative-value"
62+
"-Wswitch-default"
63+
"-Woverloaded-virtual"
64+
"-Wnon-virtual-dtor"
65+
"-Wshift-overflow=2"
66+
"-Wshift-count-overflow"
67+
"-Wwrite-strings"
68+
"-Wmissing-format-attribute"
69+
"-Wformat-nonliteral"
70+
"-Wduplicated-cond"
71+
"-Wtrampolines"
72+
"-Wsized-deallocation"
73+
"-Wlogical-op"
74+
"-Wsuggest-attribute=format"
75+
"-Wduplicated-branches"
76+
"-Wmissing-include-dirs"
77+
"-Wformat-signedness"
78+
"-Wreturn-local-addr"
79+
"-Wredundant-decls"
80+
"-Wfloat-conversion"
81+
"-fno-common"
82+
"-fno-strict-aliasing"
83+
"-Wno-return-type"
84+
"-Wno-array-bounds"
85+
"-Wno-maybe-uninitialized"
86+
"-Wno-unused-but-set-variable"
87+
"-Wno-unused-variable"
88+
"-Wno-unused-parameter"
89+
"-Wno-unused-result"
4390
)
4491

4592
# --- Project-specific Compile Flags ---

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ If no build type is given, CMake applies default optimizations and warnings.
114114
cmake -DBUILD_TESTS=OFF ..
115115
```
116116

117-
## Dependencies
117+
## Optional Functionality
118118
Some algorithms and executables are only enabled with following optional dependencies:
119119
- [Boost (≥ 1.71)]
120120
- [Eigen3 (≥ 3.4)](https://eigen.tuxfamily.org/)

apps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ endif()
5050

5151
if (COPT_FOUND)
5252
_add_executable( ilp_bsp_scheduler )
53+
_add_executable( ilp_hypergraph_partitioner )
5354
endif()
5455

5556
endif()

apps/coarser_plotter.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ int main(int argc, char *argv[]) {
5151
params.commCostVec = std::vector<v_workw_t<Graph_t>>({1, 2, 5, 10, 20, 50, 100, 200, 500, 1000});
5252
params.max_num_iteration_without_changes = 3;
5353
params.leniency = 0.005;
54-
// params.maxWeight = 15000;
54+
params.maxWeight = 15000;
55+
params.smallWeightThreshold = 4000;
56+
params.buffer_merge_mode = SarkarParams::BufferMergeMode::FULL;
5557

5658
SarkarMul<Graph_t, Graph_t> coarser;
5759
coarser.setParameters(params);
@@ -98,4 +100,4 @@ int main(int argc, char *argv[]) {
98100
}
99101

100102
return 0;
101-
};
103+
}

apps/graph_analyser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void add_graph_stats(const ComputationalDag &graph, std::ofstream &outfile) {
5858
Get_Median(edge_lengths);
5959

6060
if (graph.num_edges() != 0) {
61-
avg_edge_length = (float)sum_edge_length / (float)graph.num_edges();
61+
avg_edge_length = static_cast<float>(sum_edge_length) / static_cast<float>(graph.num_edges());
6262
}
6363

6464
// Longest Path
@@ -72,15 +72,15 @@ void add_graph_stats(const ComputationalDag &graph, std::ofstream &outfile) {
7272
// wavefront[top_level[i]] = 1;
7373
// }
7474
}
75-
float avg_wavefront = (float)graph.num_vertices() / (float)longest_path;
75+
float avg_wavefront = static_cast<float>(graph.num_vertices()) / static_cast<float>(longest_path);
7676

7777
// Average bottom distance
7878
std::vector<unsigned> bot_level = get_bottom_node_distance(graph);
7979
size_t bot_level_sum = 0;
8080
for (size_t i = 0; i < bot_level.size(); i++) {
8181
bot_level_sum += bot_level[i];
8282
}
83-
float avg_bot_level = (float)bot_level_sum / (float)bot_level.size();
83+
float avg_bot_level = static_cast<float>(bot_level_sum) / static_cast<float>(bot_level.size());
8484

8585
// // Number of Triangles
8686
// size_t number_triangles = 0;

apps/graph_generator/gen_Erdos-Renyi_graph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
5353
std::uniform_real_distribution<double> unif_log(-std::log(upper_bound), std::log(upper_bound));
5454
std::default_random_engine re;
5555

56-
for (size_t i = 0; i < num_graphs; i++) {
56+
for (size_t j = 0; j < num_graphs; j++) {
5757
// Generating the graph
5858
ComputationalDag graph;
5959
erdos_renyi_graph_gen(graph, num_vert, chance);
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
7878
}
7979
graph_name += graph_edge_size;
8080

81-
graph_name += std::to_string(i);
81+
graph_name += std::to_string(j);
8282

8383
graph_name += ".mtx";
8484

apps/graph_generator/gen_near_diag_random_graph.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ int main(int argc, char *argv[]) {
6464

6565
// Generating graph name
6666
std::string graph_name = "RandomBand_";
67-
graph_name += "p" + std::to_string((int)(100 * prob)) + "_";
68-
graph_name += "b" + std::to_string((int)bandwidth) + "_";
67+
graph_name += "p" + std::to_string(static_cast<int>(100 * prob)) + "_";
68+
graph_name += "b" + std::to_string(static_cast<int>(bandwidth)) + "_";
6969
std::string graph_size_name;
7070
if (graph.num_vertices() < 1000) {
7171
graph_size_name = std::to_string(graph.num_vertices()) + "_";
@@ -105,12 +105,12 @@ int main(int argc, char *argv[]) {
105105
graph_write << header;
106106
graph_write << std::to_string(graph.num_vertices()) + " " + std::to_string(graph.num_vertices()) + " " +
107107
std::to_string(graph.num_edges() + graph.num_vertices()) + "\n";
108-
for (VertexType i = 0; i < num_vert; i++) {
108+
for (VertexType j = 0; j < num_vert; j++) {
109109
double val = (1 - 2 * randInt(2)) * std::exp(unif_log(re));
110-
graph_write << std::to_string(i + 1) + " " + std::to_string(i + 1) + " " + std::to_string(val) + "\n";
111-
for (const auto &chld : graph.children(i)) {
110+
graph_write << std::to_string(j + 1) + " " + std::to_string(j + 1) + " " + std::to_string(val) + "\n";
111+
for (const auto &chld : graph.children(j)) {
112112
val = unif(re);
113-
graph_write << std::to_string(chld + 1) + " " + std::to_string(i + 1) + " " + std::to_string(val) +
113+
graph_write << std::to_string(chld + 1) + " " + std::to_string(j + 1) + " " + std::to_string(val) +
114114
"\n";
115115
}
116116
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
Copyright 2024 Huawei Technologies Co., Ltd.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
@author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner
17+
*/
18+
19+
#include <filesystem>
20+
#include <fstream>
21+
#include <iostream>
22+
#include <set>
23+
#include <string>
24+
#include <vector>
25+
26+
#include "osp/auxiliary/misc.hpp"
27+
#include "osp/graph_algorithms/directed_graph_path_util.hpp"
28+
#include "osp/auxiliary/io/general_file_reader.hpp"
29+
#include "osp/partitioning/model/hypergraph_utility.hpp"
30+
#include "osp/partitioning/partitioners/generic_FM.hpp"
31+
#include "osp/partitioning/partitioners/partitioning_ILP.hpp"
32+
#include "osp/partitioning/partitioners/partitioning_ILP_replication.hpp"
33+
#include "osp/graph_implementations/adj_list_impl/computational_dag_vector_impl.hpp"
34+
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
35+
#include "osp/auxiliary/io/mtx_hypergraph_file_reader.hpp"
36+
#include "osp/auxiliary/io/partitioning_file_writer.hpp"
37+
38+
39+
using namespace osp;
40+
41+
using graph = computational_dag_vector_impl_def_int_t;
42+
using hypergraph = Hypergraph_def_t;
43+
44+
int main(int argc, char *argv[]) {
45+
if (argc < 4) {
46+
std::cerr << "Usage: " << argv[0] << " <input_file> <nr_parts> <imbalance> <optional:part_repl|full_repl>"
47+
<< std::endl;
48+
return 1;
49+
}
50+
51+
std::string filename_hgraph = argv[1];
52+
std::string name_hgraph = filename_hgraph.substr(0, filename_hgraph.rfind("."));
53+
std::string file_ending = filename_hgraph.substr(filename_hgraph.rfind(".") + 1);
54+
if (!file_reader::isPathSafe(filename_hgraph)) {
55+
std::cerr << "Error: Unsafe file path (possible traversal or invalid type).\n";
56+
return 1;
57+
}
58+
59+
std::cout << name_hgraph << std::endl;
60+
61+
int nr_parts = std::stoi(argv[2]);
62+
if (nr_parts < 2 || nr_parts > 32) {
63+
std::cerr << "Argument nr_parts must be an integer between 2 and 32: " << nr_parts << std::endl;
64+
return 1;
65+
}
66+
67+
float imbalance = std::stof(argv[3]);
68+
if (imbalance < 0.01 || imbalance > .99) {
69+
std::cerr << "Argument imbalance must be a float between 0.01 and 0.99: " << imbalance << std::endl;
70+
return 1;
71+
}
72+
73+
unsigned replicate = 0;
74+
75+
if (argc > 4 && std::string(argv[4]) == "part_repl") {
76+
replicate = 1;
77+
} else if (argc > 4 && std::string(argv[4]) == "full_repl") {
78+
replicate = 2;
79+
} else if (argc > 4) {
80+
std::cerr << "Unknown argument: " << argv[4] << ". Expected 'part_repl' or 'full_repl' for replication." << std::endl;
81+
return 1;
82+
}
83+
84+
PartitioningProblem<hypergraph> instance;
85+
86+
bool file_status = true;
87+
if (file_ending == "hdag") {
88+
graph dag;
89+
file_status = file_reader::readComputationalDagHyperdagFormatDB(filename_hgraph, dag);
90+
if(file_status)
91+
instance.getHypergraph() = convert_from_cdag_as_hyperdag<hypergraph, graph>(dag);
92+
} else if (file_ending == "mtx") {
93+
file_status = file_reader::readHypergraphMartixMarketFormat(filename_hgraph, instance.getHypergraph());
94+
} else {
95+
std::cout << "Unknown file extension." << std::endl;
96+
return 1;
97+
}
98+
if (!file_status) {
99+
100+
std::cout << "Reading input file failed." << std::endl;
101+
return 1;
102+
}
103+
104+
instance.setNumberOfPartitions(static_cast<unsigned>(nr_parts));
105+
instance.setMaxWorkWeightViaImbalanceFactor(imbalance);
106+
107+
Partitioning<hypergraph> initial_partition(instance);
108+
GenericFM<hypergraph> fm;
109+
for(size_t node = 0; node < instance.getHypergraph().num_vertices(); ++node)
110+
initial_partition.setAssignedPartition(node, static_cast<unsigned>(node % static_cast<size_t>(nr_parts)));
111+
if(nr_parts == 2)
112+
fm.ImprovePartitioning(initial_partition);
113+
if(nr_parts == 4 || nr_parts == 8 || nr_parts == 16 || nr_parts == 32)
114+
fm.RecursiveFM(initial_partition);
115+
116+
if (replicate > 0) {
117+
118+
PartitioningWithReplication<hypergraph> partition(instance);
119+
HypergraphPartitioningILPWithReplication<hypergraph> partitioner;
120+
121+
for(size_t node = 0; node < instance.getHypergraph().num_vertices(); ++node)
122+
partition.setAssignedPartitions(node, {initial_partition.assignedPartition(node)});
123+
if(partition.satisfiesBalanceConstraint())
124+
partitioner.setUseInitialSolution(true);
125+
126+
partitioner.setTimeLimitSeconds(600);
127+
if(replicate == 2)
128+
partitioner.setReplicationModel(HypergraphPartitioningILPWithReplication<hypergraph>::REPLICATION_MODEL_IN_ILP::GENERAL);
129+
130+
auto solve_status = partitioner.computePartitioning(partition);
131+
132+
if (solve_status == RETURN_STATUS::OSP_SUCCESS || solve_status == RETURN_STATUS::BEST_FOUND) {
133+
file_writer::write_txt(name_hgraph + "_" + std::to_string(nr_parts) + "_" + std::to_string(imbalance) +
134+
"_ILP_rep" + std::to_string(replicate) + ".txt", partition);
135+
std::cout << "Partitioning (with replicaiton) computed with costs: " << partition.computeConnectivityCost() << std::endl;
136+
} else {
137+
std::cout << "Computing partition failed." << std::endl;
138+
return 1;
139+
}
140+
141+
} else {
142+
143+
Partitioning<hypergraph> partition(instance);
144+
HypergraphPartitioningILP<hypergraph> partitioner;
145+
146+
for(size_t node = 0; node < instance.getHypergraph().num_vertices(); ++node)
147+
partition.setAssignedPartition(node, initial_partition.assignedPartition(node));
148+
if(partition.satisfiesBalanceConstraint())
149+
partitioner.setUseInitialSolution(true);
150+
151+
partitioner.setTimeLimitSeconds(600);
152+
153+
auto solve_status = partitioner.computePartitioning(partition);
154+
155+
if (solve_status == RETURN_STATUS::OSP_SUCCESS || solve_status == RETURN_STATUS::BEST_FOUND) {
156+
file_writer::write_txt(name_hgraph + "_" + std::to_string(nr_parts) + "_" + std::to_string(imbalance) +
157+
"_ILP_rep" + std::to_string(replicate) + ".txt", partition);
158+
std::cout << "Partitioning computed with costs: " << partition.computeConnectivityCost() << std::endl;
159+
} else {
160+
std::cout << "Computing partition failed." << std::endl;
161+
return 1;
162+
}
163+
}
164+
return 0;
165+
}

apps/test_suite_runner/StatsModules/BspSptrsvStatsModule.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ bool compare_vectors(Eigen::VectorXd &v1, Eigen::VectorXd &v2) {
6666
}
6767
}
6868
return same;
69-
};
69+
}
7070

7171
template<typename TargetObjectType>
7272
class BspSptrsvStatsModule : public IStatisticModule<TargetObjectType> {
7373
public:
74-
explicit BspSptrsvStatsModule(SCHEDULE_NODE_PERMUTATION_MODES mode = NO_PERMUTE)
75-
: mode(mode) {}
74+
explicit BspSptrsvStatsModule(SCHEDULE_NODE_PERMUTATION_MODES _mode = NO_PERMUTE)
75+
: mode(_mode) {}
7676

7777

7878
std::vector<std::string> get_metric_headers() const override {

0 commit comments

Comments
 (0)