Skip to content

Commit c3ee58d

Browse files
authored
align hdag format with HyperdagDB (#10)
* align hdag format with HyperdagDB update * disable command lines by default in hdag writer
1 parent b61364d commit c3ee58d

Some content is hidden

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

50 files changed

+118176
-94165
lines changed

apps/graph_analyser.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ limitations under the License.
2727
#include "osp/graph_algorithms/directed_graph_path_util.hpp"
2828
#include "osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp"
2929
#include "osp/auxiliary/io/bsp_schedule_file_writer.hpp"
30-
#include "osp/auxiliary/io/dot_graph_file_reader.hpp"
31-
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
32-
#include "osp/auxiliary/io/mtx_graph_file_reader.hpp"
30+
#include "osp/auxiliary/io/general_file_reader.hpp"
3331

3432
using namespace osp;
3533

@@ -159,27 +157,13 @@ int main(int argc, char *argv[]) {
159157
std::cout << "Processing: " << dirEntry << std::endl;
160158

161159
std::string path_str = dirEntry.path();
162-
160+
163161
ComputationalDag graph;
164-
bool status = false;
165-
166-
if (path_str.substr(path_str.rfind(".") + 1) == "hdag") {
167-
168-
status = file_reader::readComputationalDagHyperdagFormat(dirEntry.path(), graph);
169-
170-
} else if (path_str.substr(path_str.rfind(".") + 1) == "mtx") {
171-
172-
status = file_reader::readComputationalDagMartixMarketFormat(dirEntry.path(), graph);
173-
174-
} else if (path_str.substr(path_str.rfind(".") + 1) == "dot") {
175-
176-
status = file_reader::readComputationalDagDotFormat(dirEntry.path(), graph);
177-
178-
} else {
179-
std::cout << "Unknown file ending: ." << path_str.substr(path_str.rfind(".") + 1)
180-
<< " ...assuming hyperDag format." << std::endl;
181-
status = file_reader::readComputationalDagHyperdagFormat(dirEntry.path(), graph);
182-
}
162+
bool status = file_reader::readGraph(dirEntry.path(), graph);
163+
if (!status) {
164+
std::cout << "Failed to read graph\n";
165+
return 1;
166+
}
183167

184168
if (!status)
185169
continue;

apps/graph_converter.cpp

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,40 @@ limitations under the License.
2121
#include <string>
2222

2323
#include "osp/auxiliary/io/DotFileWriter.hpp"
24-
#include "osp/auxiliary/io/dot_graph_file_reader.hpp"
25-
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
26-
#include "osp/auxiliary/io/mtx_graph_file_reader.hpp"
24+
#include "osp/auxiliary/io/general_file_reader.hpp"
25+
#include "osp/auxiliary/io/hdag_graph_file_writer.hpp"
2726
#include "osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp"
2827

2928
using namespace osp;
3029

3130
using ComputationalDag = computational_dag_edge_idx_vector_impl_def_int_t;
3231

3332
void print_usage(const char *prog_name) {
34-
std::cerr << "Usage: " << prog_name << " <input_file> <output_file>" << std::endl;
35-
std::cerr << "Converts a graph from one file format to another." << std::endl;
36-
std::cerr << "If <output_file> is '.dot', the output file will be named after the input file with a .dot extension." << std::endl;
37-
std::cerr << "Supported input formats (by extension): .hdag, .mtx, .dot" << std::endl;
38-
std::cerr << "Supported output formats (by extension): .dot" << std::endl;
33+
std::cerr << "Graph Format Converter" << std::endl;
34+
std::cerr << "----------------------" << std::endl;
35+
std::cerr << "This tool converts a directed graph from one file format to another. The desired output" << std::endl;
36+
std::cerr << "format is determined by the file extension of the output file." << std::endl
37+
<< std::endl;
38+
std::cerr << "Usage: " << prog_name << " <input_file> <output_file>" << std::endl << std::endl;
39+
std::cerr << "Arguments:" << std::endl;
40+
std::cerr << " <input_file> Path to the input graph file." << std::endl
41+
<< std::endl;
42+
std::cerr << " <output_file> Path for the output graph file. Special values of '.dot' or '.hdag' can be" << std::endl;
43+
std::cerr << " used to automatically generate the output filename by replacing the input" << std::endl;
44+
std::cerr << " file's extension with the specified one." << std::endl;
45+
std::cerr << std::endl;
46+
std::cerr << "Supported Formats:" << std::endl;
47+
std::cerr << " Input (by extension): .hdag, .mtx, .dot" << std::endl;
48+
std::cerr << " Output (by extension): .hdag, .dot" << std::endl
49+
<< std::endl;
50+
std::cerr << "The .hdag format is the HyperdagDB format. A detailed description can be found at:" << std::endl;
51+
std::cerr << "https://github.com/Algebraic-Programming/HyperDAG_DB" << std::endl
52+
<< std::endl;
53+
std::cerr << "Examples:" << std::endl;
54+
std::cerr << " " << prog_name << " my_graph.mtx my_graph.hdag" << std::endl;
55+
std::cerr << " " << prog_name << " my_graph.hdag my_graph.dot" << std::endl;
56+
std::cerr << " " << prog_name << " my_graph.mtx .dot # Creates my_graph.dot" << std::endl;
57+
std::cerr << " " << prog_name << " my_graph.dot .hdag # Creates my_graph.hdag" << std::endl;
3958
}
4059

4160
int main(int argc, char *argv[]) {
@@ -59,30 +78,23 @@ int main(int argc, char *argv[]) {
5978
return 1;
6079
}
6180
output_filename = std::filesystem::path(input_filename).replace_extension(".dot").string();
81+
} else if (output_filename_arg == ".hdag") {
82+
if (input_ext == ".hdag") {
83+
std::cerr << "Error: Input file is already a .hdag file. Cannot use '.hdag' as the output file argument in "
84+
"this case."
85+
<< std::endl;
86+
return 1;
87+
}
88+
output_filename = std::filesystem::path(input_filename).replace_extension(".hdag").string();
6289
} else {
6390
output_filename = output_filename_arg;
6491
}
6592

6693
ComputationalDag graph;
67-
bool read_success = false;
68-
6994
std::cout << "Attempting to read graph from " << input_filename << "..." << std::endl;
70-
71-
if (input_ext == ".hdag") {
72-
read_success = file_reader::readComputationalDagHyperdagFormat(input_filename, graph);
73-
} else if (input_ext == ".txt") {
74-
read_success = file_reader::readComputationalDagHyperdagFormatDB(input_filename, graph);
75-
} else if (input_ext == ".mtx") {
76-
read_success = file_reader::readComputationalDagMartixMarketFormat(input_filename, graph);
77-
} else if (input_ext == ".dot") {
78-
read_success = file_reader::readComputationalDagDotFormat(input_filename, graph);
79-
} else {
80-
std::cerr << "Unknown input file extension: " << input_ext << ". Assuming .hdag format." << std::endl;
81-
read_success = file_reader::readComputationalDagHyperdagFormat(input_filename, graph);
82-
}
83-
84-
if (!read_success) {
85-
std::cerr << "Error: Failed to read graph from " << input_filename << std::endl;
95+
bool status = file_reader::readGraph(input_filename, graph);
96+
if (!status) {
97+
std::cout << "Failed to read graph\n";
8698
return 1;
8799
}
88100

@@ -95,6 +107,8 @@ int main(int argc, char *argv[]) {
95107
if (output_ext == ".dot") {
96108
DotFileWriter writer;
97109
writer.write_graph(output_filename, graph);
110+
} else if (output_ext == ".hdag") {
111+
file_writer::writeComputationalDagHyperdagFormatDB(output_filename, graph);
98112
} else {
99113
std::cerr << "Error: Unsupported output file format: " << output_ext << std::endl;
100114
print_usage(argv[0]);

apps/ilp_bsp_scheduler.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ limitations under the License.
3030
#include "osp/auxiliary/io/DotFileWriter.hpp"
3131
#include "osp/auxiliary/io/arch_file_reader.hpp"
3232
#include "osp/auxiliary/io/bsp_schedule_file_writer.hpp"
33-
#include "osp/auxiliary/io/dot_graph_file_reader.hpp"
34-
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
35-
#include "osp/auxiliary/io/mtx_graph_file_reader.hpp"
33+
#include "osp/auxiliary/io/general_file_reader.hpp"
3634

3735
using namespace osp;
3836

@@ -73,26 +71,8 @@ int main(int argc, char *argv[]) {
7371

7472
BspInstance<ComputationalDag> instance;
7573
ComputationalDag &graph = instance.getComputationalDag();
76-
bool status_graph = false;
77-
78-
if (filename_graph.substr(filename_graph.rfind(".") + 1) == "hdag") {
79-
80-
status_graph = file_reader::readComputationalDagHyperdagFormat(filename_graph, graph);
81-
82-
} else if (filename_graph.substr(filename_graph.rfind(".") + 1) == "mtx") {
83-
84-
status_graph = file_reader::readComputationalDagMartixMarketFormat(filename_graph, graph);
85-
86-
} else if (filename_graph.substr(filename_graph.rfind(".") + 1) == "dot") {
87-
88-
status_graph = file_reader::readComputationalDagDotFormat(filename_graph, graph);
89-
90-
} else {
91-
std::cout << "Unknown file ending: ." << filename_graph.substr(filename_graph.rfind(".") + 1)
92-
<< " ...assuming hyperDag format." << std::endl;
93-
status_graph = file_reader::readComputationalDagHyperdagFormat(filename_graph, graph);
94-
}
9574

75+
bool status_graph = file_reader::readGraph(filename_graph, graph);
9676
bool status_arch = file_reader::readBspArchitecture(filename_machine, instance.getArchitecture());
9777
// instance.setDiagonalCompatibilityMatrix(graph.num_vertex_types());
9878
// instance.getArchitecture().setProcessorsWithTypes({0,0,1,1,1,1});

apps/osp.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ limitations under the License.
3131
#include "osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp"
3232
#include "osp/auxiliary/io/DotFileWriter.hpp"
3333
#include "osp/auxiliary/io/arch_file_reader.hpp"
34-
#include "osp/auxiliary/io/dot_graph_file_reader.hpp"
35-
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
36-
#include "osp/auxiliary/io/mtx_graph_file_reader.hpp"
34+
#include "osp/auxiliary/io/general_file_reader.hpp"
3735
#include "osp/auxiliary/io/bsp_schedule_file_writer.hpp"
3836
#include "test_suite_runner/ConfigParser.hpp"
3937
#include "test_suite_runner/StringToScheduler/run_bsp_scheduler.hpp"
@@ -77,28 +75,7 @@ int main(int argc, char *argv[]) {
7775
continue;
7876
}
7977

80-
bool status_graph = false;
81-
82-
if (filename_graph.substr(filename_graph.rfind(".") + 1) == "hdag") {
83-
status_graph =
84-
file_reader::readComputationalDagHyperdagFormat(filename_graph, bsp_instance.getComputationalDag());
85-
86-
} else if (filename_graph.substr(filename_graph.rfind(".") + 1) == "mtx") {
87-
88-
status_graph =
89-
file_reader::readComputationalDagMartixMarketFormat(filename_graph, bsp_instance.getComputationalDag());
90-
91-
} else if (filename_graph.substr(filename_graph.rfind(".") + 1) == "dot") {
92-
status_graph =
93-
file_reader::readComputationalDagDotFormat(filename_graph, bsp_instance.getComputationalDag());
94-
95-
} else {
96-
std::cout << "Unknown file ending: ." << filename_graph.substr(filename_graph.rfind(".") + 1)
97-
<< " ...assuming hyperDag format." << std::endl;
98-
status_graph =
99-
file_reader::readComputationalDagHyperdagFormat(filename_graph, bsp_instance.getComputationalDag());
100-
}
101-
78+
bool status_graph = file_reader::readGraph(filename_graph, bsp_instance.getComputationalDag());
10279
if (!status_graph) {
10380
std::cerr << "Reading graph files " + filename_graph << " failed." << std::endl;
10481
continue;

apps/osp_turnus.cpp

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ limitations under the License.
2121
#include <string>
2222

2323
#include "osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp"
24-
#include "osp/auxiliary/io/dot_graph_file_reader.hpp"
25-
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
26-
#include "osp/auxiliary/io/mtx_graph_file_reader.hpp"
24+
#include "osp/auxiliary/io/general_file_reader.hpp"
2725
#include "osp/auxiliary/io/bsp_schedule_file_writer.hpp"
2826
#include "osp/bsp/scheduler/GreedySchedulers/EtfScheduler.hpp"
2927
#include "osp/bsp/scheduler/GreedySchedulers/GreedyBspScheduler.hpp"
@@ -53,25 +51,7 @@ int main(int argc, char *argv[]) {
5351

5452
std::string filename_graph = argv[1];
5553

56-
bool status_graph = false;
57-
58-
if (filename_graph.substr(filename_graph.rfind(".") + 1) == "hdag") {
59-
status_graph =
60-
file_reader::readComputationalDagHyperdagFormat(filename_graph, bsp_instance.getComputationalDag());
61-
62-
} else if (filename_graph.substr(filename_graph.rfind(".") + 1) == "mtx") {
63-
64-
status_graph = file_reader::readComputationalDagMartixMarketFormat(filename_graph, bsp_instance.getComputationalDag());
65-
66-
} else if (filename_graph.substr(filename_graph.rfind(".") + 1) == "dot") {
67-
status_graph = file_reader::readComputationalDagDotFormat(filename_graph, bsp_instance.getComputationalDag());
68-
69-
} else {
70-
std::cout << "Unknown file ending: ." << filename_graph.substr(filename_graph.rfind(".") + 1)
71-
<< " ...assuming hyperDag format." << std::endl;
72-
status_graph =
73-
file_reader::readComputationalDagHyperdagFormat(filename_graph, bsp_instance.getComputationalDag());
74-
}
54+
bool status_graph = file_reader::readGraph(filename_graph, bsp_instance.getComputationalDag());
7555

7656
if (!status_graph) {
7757
std::cout << "Error while reading the graph from file: " << filename_graph << std::endl;

apps/test_suite_runner/AbstractTestSuiteRunner.hpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ limitations under the License.
3434
#include "StatsModules/IStatsModule.hpp"
3535
#include "osp/bsp/model/BspInstance.hpp"
3636
#include "osp/auxiliary/io/arch_file_reader.hpp"
37-
#include "osp/auxiliary/io/dot_graph_file_reader.hpp"
38-
#include "osp/auxiliary/io/hdag_graph_file_reader.hpp"
39-
#include "osp/auxiliary/io/mtx_graph_file_reader.hpp"
37+
#include "osp/auxiliary/io/general_file_reader.hpp"
4038

4139
//#define EIGEN_FOUND 1
4240

@@ -299,20 +297,8 @@ class AbstractTestSuiteRunner {
299297
}
300298
} else {
301299
#endif
302-
if (ext == "hdag")
303-
graph_status = file_reader::readComputationalDagHyperdagFormat(filename_graph,
304-
bsp_instance.getComputationalDag());
305-
else if (ext == "mtx")
306-
graph_status = file_reader::readComputationalDagMartixMarketFormat(
307-
filename_graph, bsp_instance.getComputationalDag());
308-
else if (ext == "dot")
309-
graph_status =
310-
file_reader::readComputationalDagDotFormat(filename_graph, bsp_instance.getComputationalDag());
311-
else {
312-
log_stream << "Unknown file ending: ." << ext << " ...assuming hyperDag format." << std::endl;
313-
graph_status = file_reader::readComputationalDagHyperdagFormat(filename_graph,
314-
bsp_instance.getComputationalDag());
315-
}
300+
graph_status = file_reader::readGraph(filename_graph, bsp_instance.getComputationalDag());
301+
316302
#ifdef EIGEN_FOUND
317303
}
318304
#endif

0 commit comments

Comments
 (0)