Skip to content

Commit e4b5ebf

Browse files
authored
Update: IO Function
Update: IO Function and Fixbug: Function DAWN::Matrix::transpose_Weighted
2 parents 24e7b77 + 144be99 commit e4b5ebf

File tree

27 files changed

+649
-628
lines changed

27 files changed

+649
-628
lines changed

algorithm/cpu/apsp_cpu/apsp_cpu.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,19 @@
77
#include <dawn/algorithm/cpu/apsp.hxx>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
std::string input_path = argv[1];
12-
std::string output_path = argv[2];
13-
std::string print = argv[3];
14-
graph.source = atoi(argv[4]);
15-
std::string weighted = argv[5];
12+
graph.source = params.source;
13+
graph.print = params.print;
14+
graph.weighted = params.weighted;
1615

1716
graph.interval = 100;
18-
19-
if (print == "true") {
20-
graph.print = true;
21-
std::cout << "Print source " << graph.source << std::endl;
22-
} else
23-
graph.print = false;
24-
25-
if (weighted == "weighted") {
26-
graph.weighted = true;
27-
} else {
28-
graph.weighted = false;
29-
}
30-
31-
graph.source = atoi(argv[6]);
3217
graph.thread = omp_get_num_threads();
33-
DAWN::Graph::createGraph(input_path, graph);
34-
float elapsed_time = DAWN::APSP_CPU::run(graph, output_path);
18+
DAWN::Graph::createGraph(params.input_path, graph);
19+
float elapsed_time = DAWN::APSP_CPU::run(graph, params.output_path);
3520
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
3621
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);
3722
printf("%-21s%3.5lf\n", "Time:", elapsed_time);
3823

3924
return 0;
4025
}
41-
42-
// ./apsp_cpu $GRAPH_DIR/XX.mtx ../output.txt false 0 unweighted//

algorithm/cpu/bc_cpu/bc_cpu.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include <dawn/algorithm/cpu/bc.hxx>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
std::string input_path = argv[1];
12-
std::string output_path = argv[2];
13-
// std::string weighted = argv[3];
1412

1513
graph.thread = omp_get_num_threads();
1614
graph.print = true;
@@ -27,13 +25,13 @@ int main(int argc, char* argv[]) {
2725
// printf("%-21s%3.5lf\n", "Time:", elapsed_time);
2826
// } else {
2927
graph.weighted = false;
30-
DAWN::Graph::createGraph(input_path, graph);
28+
DAWN::Graph::createGraph(params.input_path, graph);
3129
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
3230
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);
33-
float elapsed_time = DAWN::BC_CPU::Betweenness_Centrality(graph, output_path);
31+
float elapsed_time =
32+
DAWN::BC_CPU::Betweenness_Centrality(graph, params.output_path);
3433
printf("%-21s%3.5lf\n", "Time:", elapsed_time);
3534
// }
3635

3736
return 0;
3837
}
39-
// ./bc_cpu $GRAPH_DIR/XX.mtx ./output.txt weighted

algorithm/cpu/bfs_cpu/bfs_cpu.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,19 @@
77
#include <dawn/algorithm/cpu/bfs.hxx>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
std::string input_path = argv[1];
12-
std::string output_path = argv[2];
13-
std::string print = argv[3];
14-
graph.source = atoi(argv[4]);
15-
16-
if (print == "true") {
17-
graph.print = true;
18-
std::cout << "Print source " << graph.source << std::endl;
19-
} else {
20-
graph.print = false;
21-
}
22-
graph.thread = omp_get_num_threads();
12+
graph.source = params.source;
13+
graph.print = params.print;
2314
graph.weighted = false;
15+
graph.thread = omp_get_num_threads();
2416

25-
DAWN::Graph::createGraph(input_path, graph);
26-
27-
float elapsed_time = DAWN::BFS_CPU::run(graph, output_path);
17+
DAWN::Graph::createGraph(params.input_path, graph);
18+
float elapsed_time = DAWN::BFS_CPU::run(graph, params.output_path);
2819

2920
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
3021
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);
3122
printf("%-21s%3.5lf\n", "Time:", elapsed_time);
3223

3324
return 0;
3425
}
35-
// ./bfs_cpu $GRAPH_DIR/XX.mtx ../output.txt false 0

algorithm/cpu/cc_cpu/cc_cpu.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
#include <dawn/algorithm/cpu/cc.hxx>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
std::string input_path = argv[1];
12-
graph.source = atoi(argv[2]);
13-
std::string weighted = argv[3];
12+
graph.source = params.source;
13+
graph.print = params.print;
14+
graph.weighted = params.weighted;
1415

1516
graph.thread = omp_get_num_threads();
16-
DAWN::Graph::createGraph(input_path, graph);
17+
DAWN::Graph::createGraph(params.input_path, graph);
1718

1819
float elapsed_time = 0.0f;
19-
if (weighted == "weighted") {
20-
graph.weighted = true;
21-
20+
if (params.weighted) {
2221
float closeness_centrality =
2322
DAWN::CC_CPU::run_Weighted(graph, graph.source, elapsed_time);
2423

@@ -28,8 +27,6 @@ int main(int argc, char* argv[]) {
2827
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);
2928
printf("%-21s%3.5lf\n", "Time:", elapsed_time);
3029
} else {
31-
graph.weighted = false;
32-
3330
float closeness_centrality =
3431
DAWN::CC_CPU::run(graph, graph.source, elapsed_time);
3532

@@ -42,4 +39,3 @@ int main(int argc, char* argv[]) {
4239

4340
return 0;
4441
}
45-
// ./cc_cpu $GRAPH_DIR/XX.mtx 0 weighted

algorithm/cpu/mssp_cpu/mssp_cpu.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,24 @@
77
#include <dawn/algorithm/cpu/mssp.hxx>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
std::string input_path = argv[1];
12-
std::string output_path = argv[2];
13-
std::string print = argv[3];
14-
std::string sourceList = argv[4];
15-
std::string weighted = argv[5];
12+
graph.source = params.source;
13+
graph.print = params.print;
14+
graph.weighted = params.weighted;
1615
graph.interval = 100;
17-
if (print == "true") {
18-
graph.print = true;
19-
std::cout << "Print source " << graph.source << std::endl;
20-
} else {
21-
graph.print = false;
22-
}
23-
if (weighted == "weighted") {
24-
graph.weighted = true;
25-
} else {
26-
graph.weighted = false;
27-
}
2816
graph.thread = omp_get_num_threads();
29-
DAWN::Graph::createGraph(input_path, graph);
30-
DAWN::Graph::readList(sourceList, graph);
31-
float elapsed_time = DAWN::MSSP_CPU::run(graph, output_path);
17+
if (params.sourceList_path.empty()) {
18+
std::cerr << "Invalid value for sourceList_path option.\n";
19+
exit(EXIT_FAILURE);
20+
}
21+
22+
DAWN::Graph::createGraph(params.input_path, graph);
23+
DAWN::IO::readList(params.sourceList_path, graph);
24+
float elapsed_time = DAWN::MSSP_CPU::run(graph, params.output_path);
3225
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
3326
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);
3427
printf("%-21s%3.5lf\n", "Time:", elapsed_time);
3528

3629
return 0;
3730
}
38-
// ./mssp_cpu $GRAPH_DIR/XX.mtx ../output.txt false ./sourceList.txt
39-
// unweighted
40-
41-
// ./mssp_cpu $GRAPH_DIR/XX.mtx ../output.txt false ./sourceList.txt weighted

algorithm/cpu/sssp_cpu/sssp_cpu.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@
77
#include <dawn/algorithm/cpu/sssp.hxx>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
std::string input_path = argv[1];
12-
std::string output_path = argv[2];
13-
std::string print = argv[3];
12+
graph.source = params.source;
13+
graph.print = params.print;
1414
graph.source = atoi(argv[4]);
1515

16-
if (print == "true") {
17-
graph.print = true;
18-
std::cout << "Print source " << graph.source << std::endl;
19-
} else {
20-
graph.print = false;
21-
}
2216
graph.thread = omp_get_num_threads();
2317
graph.weighted = true;
2418

25-
DAWN::Graph::createGraph(input_path, graph);
19+
DAWN::Graph::createGraph(params.input_path, graph);
2620

27-
float elapsed_time = DAWN::SSSP_CPU::run(graph, output_path);
21+
float elapsed_time = DAWN::SSSP_CPU::run(graph, params.output_path);
2822

2923
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
3024
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);

algorithm/gpu/apsp_gpu/apsp_gpu.cu

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,30 @@
66
*/
77
#include <dawn/algorithm/gpu/apsp.cuh>
88
int main(int argc, char* argv[]) {
9+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
910
DAWN::Graph::Graph_t graph;
10-
11-
std::string input_path = argv[1];
12-
std::string output_path = argv[2];
13-
graph.stream = atoi(argv[3]);
14-
graph.block_size = atoi(argv[4]);
15-
std::string print = argv[5];
16-
graph.source = atoi(argv[6]);
17-
std::string weighted = argv[7];
18-
11+
graph.source = params.source;
12+
graph.print = params.print;
13+
graph.weighted = params.weighted;
14+
graph.thread = 1;
15+
graph.stream = 4;
16+
graph.block_size = 1024;
1917
graph.interval = 100;
2018

21-
if (print == "true") {
22-
graph.print = true;
23-
std::cout << "Print source " << graph.source << std::endl;
24-
} else {
25-
graph.print = false;
26-
}
27-
28-
DAWN::Graph::createGraph(input_path, graph);
29-
30-
if (weighted == "weighted") {
31-
graph.weighted = true;
32-
33-
float elapsed_time = DAWN::APSP_GPU::run_Weighted(graph, output_path);
19+
DAWN::Graph::createGraph(params.input_path, graph);
3420

21+
if (graph.weighted) {
22+
float elapsed_time =
23+
DAWN::APSP_GPU::run_Weighted(graph, params.output_path);
3524
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
3625
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);
3726
printf("%-21s%3.5lf\n", "Time:", elapsed_time);
3827
} else {
39-
graph.weighted = false;
40-
41-
float elapsed_time = DAWN::APSP_GPU::run(graph, output_path);
42-
28+
float elapsed_time = DAWN::APSP_GPU::run(graph, params.output_path);
4329
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
4430
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);
4531
printf("%-21s%3.5lf\n", "Time:", elapsed_time);
4632
}
4733

4834
return 0;
49-
}
50-
//./apsp_gpu $GRAPH_DIR/XXX.mtx ../output.txt 8 1024 false 0 unweighted
51-
//./apsp_gpu $GRAPH_DIR/XXX.mtx ../output.txt 8 1024 false 0 weighted
35+
}

algorithm/gpu/bfs_gpu/bfs_gpu.cu

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,18 @@
77
#include <dawn/algorithm/gpu/bfs.cuh>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
12-
std::string input_path = argv[1];
13-
std::string output_path = argv[2];
14-
graph.block_size = atoi(argv[3]);
15-
std::string print = argv[4];
16-
graph.source = atoi(argv[5]);
17-
12+
graph.source = params.source;
13+
graph.print = params.print;
1814
graph.thread = 1;
1915
graph.stream = 1;
16+
graph.block_size = 1024;
2017
graph.weighted = false;
2118

22-
if (print == "true") {
23-
graph.print = true;
24-
std::cout << "Print source " << graph.source << std::endl;
25-
} else {
26-
graph.print = false;
27-
}
28-
29-
DAWN::Graph::createGraph(input_path, graph);
19+
DAWN::Graph::createGraph(params.input_path, graph);
3020

31-
float elapsed_time = DAWN::BFS_GPU::run(graph, output_path);
21+
float elapsed_time = DAWN::BFS_GPU::run(graph, params.output_path);
3222

3323
printf("%-21s%3.5d\n", "Nodes:", graph.rows);
3424
printf("%-21s%3.5ld\n", "Edges:", graph.nnz);

algorithm/gpu/cc_gpu/cc_gpu.cu

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,24 @@
77
#include <dawn/algorithm/gpu/cc.cuh>
88

99
int main(int argc, char* argv[]) {
10+
DAWN::IO::parameters_t params = DAWN::IO::parameters(argc, argv);
1011
DAWN::Graph::Graph_t graph;
11-
12-
std::string input_path = argv[1];
13-
graph.block_size = atoi(argv[2]);
14-
graph.source = atoi(argv[3]);
15-
std::string weighted = argv[4];
16-
12+
graph.source = params.source;
13+
graph.print = params.print;
14+
graph.weighted = params.weighted;
1715
graph.thread = 1;
1816
graph.stream = 1;
17+
graph.block_size = 1024;
1918

20-
DAWN::Graph::createGraph(input_path, graph);
21-
22-
if (weighted == "true") {
23-
graph.weighted = true;
19+
DAWN::Graph::createGraph(params.input_path, graph);
2420

21+
if (graph.weighted) {
2522
float closeness_centrality =
2623
DAWN::CC_GPU::run_Weighted(graph, graph.source);
27-
2824
printf("%-21s%3.5d\n", "Source:", graph.source);
2925
printf("%-21s%3.5lf\n", "Closeness Centrality:", closeness_centrality);
3026
} else {
31-
graph.weighted = false;
32-
3327
float closeness_centrality = DAWN::CC_GPU::run(graph, graph.source);
34-
3528
printf("%-21s%3.5d\n", "Source:", graph.source);
3629
printf("%-21s%3.5lf\n", "Closeness Centrality:", closeness_centrality);
3730
}

0 commit comments

Comments
 (0)