00001
00025 #ifndef GALOIS_GRAPH_UTIL_H
00026 #define GALOIS_GRAPH_UTIL_H
00027
00028 #include "Galois/Galois.h"
00029 #include "Galois/Graph/Details.h"
00030
00031 namespace Galois {
00032 namespace Graph {
00033
00039 template<typename GraphTy, typename... Args>
00040 void readGraph(GraphTy& graph, Args&&... args) {
00041 typename GraphTy::read_tag tag;
00042 readGraphDispatch(graph, tag, std::forward<Args>(args)...);
00043 }
00044
00045 template<typename GraphTy>
00046 void readGraphDispatch(GraphTy& graph, read_default_graph_tag tag, const std::string& filename) {
00047 FileGraph f;
00048 f.structureFromFileInterleaved<typename GraphTy::edge_data_type>(filename);
00049 readGraphDispatch(graph, tag, f);
00050 }
00051
00052 template<typename GraphTy>
00053 struct ReadGraphConstructFrom {
00054 GraphTy& graph;
00055 FileGraph& f;
00056 ReadGraphConstructFrom(GraphTy& g, FileGraph& _f): graph(g), f(_f) { }
00057 void operator()(unsigned tid, unsigned total) {
00058 graph.constructFrom(f, tid, total);
00059 }
00060 };
00061
00062 template<typename GraphTy, typename Aux>
00063 struct ReadGraphConstructNodesFrom {
00064 GraphTy& graph;
00065 FileGraph& f;
00066 Aux& aux;
00067 ReadGraphConstructNodesFrom(GraphTy& g, FileGraph& _f, Aux& a): graph(g), f(_f), aux(a) { }
00068 void operator()(unsigned tid, unsigned total) {
00069 graph.constructNodesFrom(f, tid, total, aux);
00070 }
00071 };
00072
00073 template<typename GraphTy, typename Aux>
00074 struct ReadGraphConstructEdgesFrom {
00075 GraphTy& graph;
00076 FileGraph& f;
00077 Aux& aux;
00078 ReadGraphConstructEdgesFrom(GraphTy& g, FileGraph& _f, Aux& a): graph(g), f(_f), aux(a) { }
00079 void operator()(unsigned tid, unsigned total) {
00080 graph.constructEdgesFrom(f, tid, total, aux);
00081 }
00082 };
00083
00084
00085 template<typename GraphTy>
00086 void readGraphDispatch(GraphTy& graph, read_default_graph_tag, FileGraph& f) {
00087 graph.allocateFrom(f);
00088
00089 Galois::on_each(ReadGraphConstructFrom<GraphTy>(graph, f));
00090 }
00091
00092 template<typename GraphTy>
00093 void readGraphDispatch(GraphTy& graph, read_with_aux_graph_tag tag, const std::string& filename) {
00094 FileGraph f;
00095 f.structureFromFileInterleaved<typename GraphTy::edge_data_type>(filename);
00096 readGraphDispatch(graph, tag, f);
00097 }
00098
00099 template<typename GraphTy>
00100 void readGraphDispatch(GraphTy& graph, read_with_aux_graph_tag, FileGraph& f) {
00101 typedef typename GraphTy::ReadGraphAuxData Aux;
00102
00103 Aux aux;
00104 graph.allocateFrom(f, aux);
00105
00106 Galois::on_each(ReadGraphConstructNodesFrom<GraphTy, Aux>(graph, f, aux));
00107 Galois::on_each(ReadGraphConstructEdgesFrom<GraphTy, Aux>(graph, f, aux));
00108 }
00109
00110 template<typename GraphTy>
00111 void readGraphDispatch(GraphTy& graph, read_lc_inout_graph_tag, const std::string& f1, const std::string& f2) {
00112 graph.createAsymmetric();
00113
00114 typename GraphTy::out_graph_type::read_tag tag1;
00115 readGraphDispatch(graph, tag1, f1);
00116
00117 typename GraphTy::in_graph_type::read_tag tag2;
00118 readGraphDispatch(graph.inGraph, tag2, f2);
00119 }
00120
00121 template<typename GraphTy>
00122 void readGraphDispatch(GraphTy& graph, read_lc_inout_graph_tag, const std::string& f1) {
00123 typename GraphTy::out_graph_type::read_tag tag1;
00124 readGraphDispatch(graph, tag1, f1);
00125 }
00126
00127 }
00128 }
00129
00130 #endif