-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (73 loc) · 2.8 KB
/
main.cpp
File metadata and controls
84 lines (73 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "delta_stepping.h"
#include <iostream>
#include <fstream>
#include <mpi.h>
#include "common.h"
constexpr bool report_execution_time = false;
constexpr bool print_distances = true;
constexpr bool report_optimizations = false;
int world_rank, world_size;
int main(int argc, char* argv[]) noexcept {
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
if (argc < 3) {
if (world_rank == 0) {
std::cerr << "Usage: " << argv[0] << " <input_file> <output_file>" << std::endl;
}
MPI_Abort(MPI_COMM_WORLD, 1);
}
const std::string input_file = argv[1], output_file = argv[2];
std::ifstream input(input_file, std::ios::binary);
if (!input.is_open()) {
if (world_rank == 0) {
std::cerr << "Failed to open input file " << input_file << std::endl;
}
MPI_Abort(MPI_COMM_WORLD, 1);
}
int global_vertex_count, first_vertex, last_vertex;
input >> global_vertex_count >> first_vertex >> last_vertex;
input.close();
const int max_graph_chunk_size = (global_vertex_count + world_size - 1) / world_size;
auto run_and_report = [&](auto&& delta_stepping) {
double start_time, end_time;
if constexpr (report_execution_time) {
MPI_Barrier(MPI_COMM_WORLD);
start_time = MPI_Wtime();
}
delta_stepping.run();
if constexpr (report_execution_time) {
end_time = MPI_Wtime();
double min_start_time, max_end_time;
MPI_Reduce(&end_time, &max_end_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
MPI_Reduce(&start_time, &min_start_time, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD);
if (world_rank == 0) {
// Time in ms
std::cerr << (max_end_time - min_start_time) * 1000;
}
}
if constexpr (print_distances) {
delta_stepping.print_distances(output_file);
}
};
if (dynamic_index_width && max_graph_chunk_size <= (1 << 16)) {
DeltaStepping<uint16_t> delta_stepping(global_vertex_count, first_vertex, last_vertex, input_file);
run_and_report(delta_stepping);
} else {
DeltaStepping<uint32_t> delta_stepping(global_vertex_count, first_vertex, last_vertex, input_file);
run_and_report(delta_stepping);
}
if constexpr (report_optimizations) {
if (world_rank == 0) {
std::cerr << "," << OPT_DELTA
<< "," << OPT_HYBRIDIZATION_THRESHOLD
<< "," << ios
<< "," << pruning
<< "," << hybridization
<< "," << dynamic_index_width
<< std::endl;
}
}
MPI_Finalize();
return 0;
}