Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReadGraph.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_GRAPHS_READGRAPH_H
21 #define GALOIS_GRAPHS_READGRAPH_H
22 
23 #include "galois/config.h"
24 #include "galois/Galois.h"
25 #include "galois/graphs/Details.h"
27 #include "galois/Timer.h"
28 
29 namespace galois {
30 namespace graphs {
31 
37 template <typename GraphTy, typename... Args>
38 void readGraph(GraphTy& graph, Args&&... args) {
39  typename GraphTy::read_tag tag;
40  readGraphDispatch(graph, tag, std::forward<Args>(args)...);
41 }
42 
43 template <typename GraphTy>
44 void readGraphDispatch(GraphTy& graph, read_default_graph_tag tag,
45  const std::string& filename,
46  const bool readUnweighted = false) {
47  FileGraph f;
48  if (readUnweighted) {
52  f.fromFileInterleaved<void>(filename);
53  } else {
54  f.fromFileInterleaved<typename GraphTy::file_edge_data_type>(filename);
55  }
56  readGraphDispatch(graph, tag, f, readUnweighted);
57 }
58 
59 template <typename GraphTy>
61  GraphTy& graph;
63  bool readUnweighted = false;
64  ReadGraphConstructFrom(GraphTy& g, FileGraph& _f) : graph(g), f(_f) {}
65  ReadGraphConstructFrom(GraphTy& g, FileGraph& _f, bool _readUnweighted)
66  : graph(g), f(_f), readUnweighted(_readUnweighted) {}
67  void operator()(unsigned tid, unsigned total) {
68  graph.constructFrom(f, tid, total, readUnweighted);
69  }
70 };
71 
72 template <typename GraphTy>
74  const bool readUnweighted = false) {
75  graph.allocateFrom(f);
76 
77  ReadGraphConstructFrom<GraphTy> reader(graph, f, readUnweighted);
78  galois::on_each(reader);
79 }
80 
81 template <typename GraphTy, typename Aux>
83  GraphTy& graph;
85  Aux& aux;
86  ReadGraphConstructNodesFrom(GraphTy& g, FileGraph& _f, Aux& a)
87  : graph(g), f(_f), aux(a) {}
88  void operator()(unsigned tid, unsigned total) {
89  graph.constructNodesFrom(f, tid, total, aux);
90  }
91 };
92 
93 template <typename GraphTy, typename Aux>
95  GraphTy& graph;
97  Aux& aux;
98  ReadGraphConstructEdgesFrom(GraphTy& g, FileGraph& _f, Aux& a)
99  : graph(g), f(_f), aux(a) {}
100  void operator()(unsigned tid, unsigned total) {
101  graph.constructEdgesFrom(f, tid, total, aux);
102  }
103 };
104 
105 template <typename GraphTy>
107  const std::string& filename) {
108  FileGraph f;
109  f.fromFileInterleaved<typename GraphTy::file_edge_data_type>(filename);
110  readGraphDispatch(graph, tag, f);
111 }
112 
113 template <typename GraphTy>
115  typedef typename GraphTy::ReadGraphAuxData Aux;
116 
117  Aux aux;
118  graph.allocateFrom(f, aux);
119 
120  ReadGraphConstructNodesFrom<GraphTy, Aux> nodeReader(graph, f, aux);
121  galois::on_each(nodeReader);
122 
123  ReadGraphConstructEdgesFrom<GraphTy, Aux> edgeReader(graph, f, aux);
124  galois::on_each(edgeReader);
125 }
126 
127 template <typename GraphTy, typename Aux>
129  GraphTy& graph;
131  Aux& aux;
132  ReadGraphConstructOutEdgesFrom(GraphTy& g, FileGraph& _f, Aux& a)
133  : graph(g), f(_f), aux(a) {}
134  void operator()(unsigned tid, unsigned total) {
135  graph.constructOutEdgesFrom(f, tid, total, aux);
136  }
137 };
138 
139 template <typename GraphTy, typename Aux>
141  GraphTy& graph;
143  Aux& aux;
144  ReadGraphConstructInEdgesFrom(GraphTy& g, FileGraph& _f, Aux& a)
145  : graph(g), f(_f), aux(a) {}
146  void operator()(unsigned tid, unsigned total) {
147  graph.constructInEdgesFrom(f, tid, total, aux);
148  }
149 };
150 
151 template <typename GraphTy>
153  FileGraph& f) {
154  typedef typename GraphTy::ReadGraphAuxData Aux;
155  constexpr static const bool profile = false;
156 
157  galois::CondStatTimer<profile> TAlloc("AllocateAux");
158  TAlloc.start();
159  Aux* auxPtr = new Aux;
160  graph.allocateFrom(f, *auxPtr);
161  TAlloc.stop();
162 
163  galois::CondStatTimer<profile> TNode("ConstructNode");
164  TNode.start();
165  ReadGraphConstructNodesFrom<GraphTy, Aux> nodeReader(graph, f, *auxPtr);
166  galois::on_each(nodeReader);
167  TNode.stop();
168 
169  galois::CondStatTimer<profile> TOutEdge("ConstructOutEdge");
170  TOutEdge.start();
171  ReadGraphConstructOutEdgesFrom<GraphTy, Aux> outEdgeReader(graph, f, *auxPtr);
172  galois::on_each(outEdgeReader);
173  TOutEdge.stop();
174 
175  galois::CondStatTimer<profile> TInEdge("ConstructInEdge");
176  TInEdge.start();
177  ReadGraphConstructInEdgesFrom<GraphTy, Aux> inEdgeReader(graph, f, *auxPtr);
178  galois::on_each(inEdgeReader);
179  TInEdge.stop();
180 
181  galois::CondStatTimer<profile> TDestruct("DestructAux");
182  TDestruct.start();
183  delete auxPtr;
184  TDestruct.stop();
185 }
186 
187 template <typename GraphTy>
189  const std::string& filename) {
190  FileGraph f;
191  f.fromFileInterleaved<typename GraphTy::file_edge_data_type>(filename);
192  readGraphDispatch(graph, tag, f);
193 }
194 
195 template <typename GraphTy>
197  const std::string& f1, const std::string& f2) {
198  graph.createAsymmetric();
199 
200  typename GraphTy::out_graph_type::read_tag tag1;
201  readGraphDispatch(graph, tag1, f1);
202 
203  typename GraphTy::in_graph_type::read_tag tag2;
204  readGraphDispatch(graph.inGraph, tag2, f2);
205 }
206 
207 template <typename GraphTy>
209  FileGraph& f2) {
210  graph.createAsymmetric();
211 
212  typename GraphTy::out_graph_type::read_tag tag1;
213  readGraphDispatch(graph, tag1, f1);
214 
215  typename GraphTy::in_graph_type::read_tag tag2;
216  readGraphDispatch(graph.inGraph, tag2, f2);
217 }
218 
219 template <typename GraphTy>
221  typename GraphTy::out_graph_type::read_tag tag1;
222  readGraphDispatch(graph, tag1, f1);
223 }
224 
225 template <typename GraphTy>
227  const std::string& f1) {
228  typename GraphTy::out_graph_type::read_tag tag1;
229  readGraphDispatch(graph, tag1, f1);
230 }
231 
232 } // namespace graphs
233 } // namespace galois
234 
235 #endif
Aux & aux
Definition: ReadGraph.h:97
FileGraph & f
Definition: ReadGraph.h:62
GraphTy & graph
Definition: ReadGraph.h:129
GraphTy & graph
Definition: ReadGraph.h:95
GraphTy & graph
Definition: ReadGraph.h:61
Contains FileGraph and FileGraphWriter class declarations.
GraphTy & graph
Definition: ReadGraph.h:83
Definition: ReadGraph.h:60
ReadGraphConstructOutEdgesFrom(GraphTy &g, FileGraph &_f, Aux &a)
Definition: ReadGraph.h:132
void operator()(unsigned tid, unsigned total)
Definition: ReadGraph.h:134
ReadGraphConstructFrom(GraphTy &g, FileGraph &_f)
Definition: ReadGraph.h:64
void readGraph(GraphTy &graph, Args &&...args)
Allocates and constructs a graph from a file.
Definition: ReadGraph.h:38
void readGraphDispatch(GraphTy &graph, read_oc_immutable_edge_graph_tag, Args &&...args)
Definition: OCGraph.h:587
FileGraph & f
Definition: ReadGraph.h:130
FileGraph & f
Definition: ReadGraph.h:96
void operator()(unsigned tid, unsigned total)
Definition: ReadGraph.h:100
void operator()(unsigned tid, unsigned total)
Definition: ReadGraph.h:67
ReadGraphConstructFrom(GraphTy &g, FileGraph &_f, bool _readUnweighted)
Definition: ReadGraph.h:65
ReadGraphConstructEdgesFrom(GraphTy &g, FileGraph &_f, Aux &a)
Definition: ReadGraph.h:98
bool readUnweighted
Definition: ReadGraph.h:63
Aux & aux
Definition: ReadGraph.h:131
void operator()(unsigned tid, unsigned total)
Definition: ReadGraph.h:88
FileGraph & f
Definition: ReadGraph.h:84
Aux & aux
Definition: ReadGraph.h:143
Aux & aux
Definition: ReadGraph.h:85
FileGraph & f
Definition: ReadGraph.h:142
void start()
Definition: Timer.cpp:82
void on_each(FunctionTy &&fn, const Args &...args)
Low-level parallel loop.
Definition: Loops.h:86
ReadGraphConstructInEdgesFrom(GraphTy &g, FileGraph &_f, Aux &a)
Definition: ReadGraph.h:144
void operator()(unsigned tid, unsigned total)
Definition: ReadGraph.h:146
Graph that mmaps Galois gr files for access.
Definition: FileGraph.h:57
GraphTy & graph
Definition: ReadGraph.h:141
Definition: Timer.h:88
void stop()
Definition: Timer.cpp:87
ReadGraphConstructNodesFrom(GraphTy &g, FileGraph &_f, Aux &a)
Definition: ReadGraph.h:86