#include #include #include #include #include using namespace std; // CSR graph class csr_graph { public: unsigned int nodes; unsigned int edges; unsigned int *node_array; unsigned int *edge_array; int *node_data; }; csr_graph parse_bin_files(string base) { csr_graph ret; ifstream nodes_edges_file(base + "/num_nodes_edges.txt"); unsigned int nodes, edges; auto start = chrono::system_clock::now(); nodes_edges_file >> nodes; nodes_edges_file >> edges; nodes_edges_file.close(); cout << "Found " << nodes << " " << edges << "\n"; ret.nodes = nodes; ret.edges = edges; ret.node_array = (unsigned int*) malloc(sizeof(unsigned int) * (ret.nodes + 1)); ret.edge_array = (unsigned int*) malloc(sizeof(unsigned int) * (ret.edges)); ret.node_data = (int*) malloc(sizeof(int) * (ret.edges)); ifstream node_array_file; node_array_file.open(base + "node_array.bin", ios::in | ios::binary); if (!node_array_file.is_open()) { assert(0); } node_array_file.read((char *)ret.node_array, (ret.nodes + 1) * sizeof(unsigned int)); node_array_file.close(); ifstream edge_array_file; edge_array_file.open(base + "edge_array.bin", ios::in | ios::binary); if (!edge_array_file.is_open()) { assert(0); } edge_array_file.read((char*)ret.edge_array, ret.edges * sizeof(unsigned int)); edge_array_file.close(); ifstream edge_values_file; edge_values_file.open(base + "edge_values.bin", ios::in | ios::binary); if (!edge_values_file.is_open()) { assert(0); } edge_values_file.read((char*)ret.node_data, sizeof(int) * ret.edges); edge_values_file.close(); auto end = std::chrono::system_clock::now(); chrono::duration elapsed_seconds = end-start; cout << "Reading graph elapsed time: " << elapsed_seconds.count() << "s\n"; return ret; } int main(int argc, char** argv) { char *graph_fname; csr_graph G; graph_fname = argv[1]; parse_bin_files(graph_fname); return 0; }