Chris@16
|
1 // Copyright (C) 2006 The Trustees of Indiana University.
|
Chris@16
|
2
|
Chris@16
|
3 // Use, modification and distribution is subject to the Boost Software
|
Chris@16
|
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6
|
Chris@16
|
7 // Authors: Douglas Gregor
|
Chris@16
|
8 // Jeremiah Willcock
|
Chris@16
|
9 // Andrew Lumsdaine
|
Chris@16
|
10
|
Chris@16
|
11 // Distributed compressed sparse row graph type
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef BOOST_GRAPH_DISTRIBUTED_CSR_HPP
|
Chris@16
|
14 #define BOOST_GRAPH_DISTRIBUTED_CSR_HPP
|
Chris@16
|
15
|
Chris@16
|
16 #ifndef BOOST_GRAPH_USE_MPI
|
Chris@16
|
17 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
|
Chris@16
|
18 #endif
|
Chris@16
|
19
|
Chris@16
|
20 #include <boost/assert.hpp>
|
Chris@16
|
21 #include <boost/graph/compressed_sparse_row_graph.hpp>
|
Chris@16
|
22 #include <boost/graph/distributed/selector.hpp>
|
Chris@16
|
23 #include <boost/mpl/if.hpp>
|
Chris@16
|
24 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
25 #include <boost/graph/distributed/concepts.hpp>
|
Chris@16
|
26 #include <boost/graph/parallel/properties.hpp>
|
Chris@16
|
27 #include <boost/graph/parallel/distribution.hpp>
|
Chris@16
|
28 #include <boost/property_map/parallel/local_property_map.hpp>
|
Chris@16
|
29 #include <boost/property_map/parallel/distributed_property_map.hpp>
|
Chris@16
|
30
|
Chris@16
|
31 namespace boost {
|
Chris@16
|
32
|
Chris@16
|
33 // Distributed and sequential inplace ctors have the same signature so
|
Chris@16
|
34 // we need a separate tag for distributed inplace ctors
|
Chris@16
|
35 enum distributed_construct_inplace_from_sources_and_targets_t
|
Chris@16
|
36 {distributed_construct_inplace_from_sources_and_targets};
|
Chris@16
|
37
|
Chris@16
|
38 // The number of bits we reserve for the processor ID.
|
Chris@16
|
39 // DPG TBD: This is a hack. It will eventually be a run-time quantity.
|
Chris@16
|
40 static const int processor_bits = 8;
|
Chris@16
|
41
|
Chris@16
|
42 // Tag class for a distributed CSR graph
|
Chris@16
|
43 struct distributed_csr_tag
|
Chris@16
|
44 : public virtual distributed_graph_tag,
|
Chris@16
|
45 public virtual distributed_vertex_list_graph_tag,
|
Chris@16
|
46 public virtual distributed_edge_list_graph_tag,
|
Chris@16
|
47 public virtual incidence_graph_tag,
|
Chris@16
|
48 public virtual adjacency_graph_tag {};
|
Chris@16
|
49
|
Chris@16
|
50 template<typename VertexProperty, typename EdgeProperty,
|
Chris@16
|
51 typename GraphProperty, typename ProcessGroup, typename InVertex,
|
Chris@16
|
52 typename InDistribution, typename InEdgeIndex>
|
Chris@16
|
53 class compressed_sparse_row_graph<
|
Chris@16
|
54 directedS, VertexProperty, EdgeProperty, GraphProperty,
|
Chris@16
|
55 distributedS<ProcessGroup, InVertex, InDistribution>,
|
Chris@16
|
56 InEdgeIndex>
|
Chris@16
|
57 {
|
Chris@16
|
58 typedef compressed_sparse_row_graph self_type;
|
Chris@16
|
59
|
Chris@16
|
60 private:
|
Chris@16
|
61 /**
|
Chris@16
|
62 * Determine the type used to represent vertices in the graph. If
|
Chris@16
|
63 * the user has overridden the default, use the user's
|
Chris@16
|
64 * parameter. Otherwise, fall back to std::size_t.
|
Chris@16
|
65 */
|
Chris@16
|
66 typedef typename mpl::if_<is_same<InVertex, defaultS>,
|
Chris@16
|
67 std::size_t,
|
Chris@16
|
68 InVertex>::type Vertex;
|
Chris@16
|
69
|
Chris@16
|
70 /**
|
Chris@16
|
71 * Determine the type used to represent edges in the graph. If
|
Chris@16
|
72 * the user has overridden the default (which is to be the same as
|
Chris@16
|
73 * the distributed vertex selector type), use the user's
|
Chris@16
|
74 * parameter. Otherwise, fall back to the value of @c Vertex.
|
Chris@16
|
75 */
|
Chris@16
|
76 typedef typename mpl::if_<is_same<InEdgeIndex,
|
Chris@16
|
77 distributedS<ProcessGroup, InVertex,
|
Chris@16
|
78 InDistribution> >,
|
Chris@16
|
79 Vertex,
|
Chris@16
|
80 InEdgeIndex>::type EdgeIndex;
|
Chris@16
|
81
|
Chris@16
|
82 public:
|
Chris@16
|
83 /**
|
Chris@16
|
84 * The type of the CSR graph that will be stored locally.
|
Chris@16
|
85 */
|
Chris@16
|
86 typedef compressed_sparse_row_graph<directedS, VertexProperty, EdgeProperty,
|
Chris@16
|
87 GraphProperty, Vertex, EdgeIndex>
|
Chris@16
|
88 base_type;
|
Chris@16
|
89
|
Chris@16
|
90 // -----------------------------------------------------------------
|
Chris@16
|
91 // Graph concept requirements
|
Chris@16
|
92 typedef Vertex vertex_descriptor;
|
Chris@16
|
93 typedef typename graph_traits<base_type>::edge_descriptor edge_descriptor;
|
Chris@16
|
94 typedef directed_tag directed_category;
|
Chris@16
|
95 typedef allow_parallel_edge_tag edge_parallel_category;
|
Chris@16
|
96 typedef distributed_csr_tag traversal_category;
|
Chris@16
|
97 static vertex_descriptor null_vertex();
|
Chris@16
|
98
|
Chris@16
|
99 // -----------------------------------------------------------------
|
Chris@16
|
100 // Distributed Vertex List Graph concept requirements
|
Chris@16
|
101 typedef Vertex vertices_size_type;
|
Chris@16
|
102 class vertex_iterator;
|
Chris@16
|
103
|
Chris@16
|
104 // -----------------------------------------------------------------
|
Chris@16
|
105 // Distributed Edge List Graph concept requirements
|
Chris@16
|
106 typedef EdgeIndex edges_size_type;
|
Chris@16
|
107 class edge_iterator;
|
Chris@16
|
108
|
Chris@16
|
109 // -----------------------------------------------------------------
|
Chris@16
|
110 // Incidence Graph concept requirements
|
Chris@16
|
111 typedef typename graph_traits<base_type>::out_edge_iterator
|
Chris@16
|
112 out_edge_iterator;
|
Chris@16
|
113 typedef typename graph_traits<base_type>::degree_size_type
|
Chris@16
|
114 degree_size_type;
|
Chris@16
|
115
|
Chris@16
|
116 // -----------------------------------------------------------------
|
Chris@16
|
117 // Adjacency Graph concept requirements
|
Chris@16
|
118 typedef typename graph_traits<base_type>::adjacency_iterator
|
Chris@16
|
119 adjacency_iterator;
|
Chris@16
|
120
|
Chris@16
|
121 // Note: This graph type does not model Bidirectional Graph.
|
Chris@16
|
122 // However, this typedef is required to satisfy graph_traits.
|
Chris@16
|
123 typedef void in_edge_iterator;
|
Chris@16
|
124
|
Chris@16
|
125 // -----------------------------------------------------------------
|
Chris@16
|
126 // Distributed Container concept requirements
|
Chris@16
|
127 typedef ProcessGroup process_group_type;
|
Chris@16
|
128 typedef boost::parallel::variant_distribution<process_group_type, Vertex>
|
Chris@16
|
129 distribution_type;
|
Chris@16
|
130
|
Chris@16
|
131 // -----------------------------------------------------------------
|
Chris@16
|
132 // Workarounds
|
Chris@16
|
133 // NOTE: This graph type does not have old-style graph properties. It only
|
Chris@16
|
134 // accepts bundles.
|
Chris@16
|
135 typedef no_property vertex_property_type;
|
Chris@16
|
136 typedef no_property edge_property_type;
|
Chris@16
|
137 typedef no_property graph_property_type;
|
Chris@16
|
138 typedef typename mpl::if_<is_void<VertexProperty>,
|
Chris@16
|
139 void****,
|
Chris@16
|
140 VertexProperty>::type vertex_bundled;
|
Chris@16
|
141 typedef typename mpl::if_<is_void<EdgeProperty>,
|
Chris@16
|
142 void****,
|
Chris@16
|
143 EdgeProperty>::type edge_bundled;
|
Chris@16
|
144 typedef typename mpl::if_<is_void<GraphProperty>,
|
Chris@16
|
145 void****,
|
Chris@16
|
146 GraphProperty>::type graph_bundled;
|
Chris@16
|
147
|
Chris@16
|
148 // -----------------------------------------------------------------
|
Chris@16
|
149 // Useful types
|
Chris@16
|
150 typedef typename ProcessGroup::process_id_type process_id_type;
|
Chris@16
|
151
|
Chris@16
|
152 // -----------------------------------------------------------------
|
Chris@16
|
153 // Graph constructors
|
Chris@16
|
154 compressed_sparse_row_graph(const ProcessGroup& pg = ProcessGroup())
|
Chris@16
|
155 : m_process_group(pg), m_distribution(parallel::block(pg, 0)) {}
|
Chris@16
|
156
|
Chris@16
|
157 compressed_sparse_row_graph(const GraphProperty& prop,
|
Chris@16
|
158 const ProcessGroup& pg = ProcessGroup())
|
Chris@16
|
159 : m_process_group(pg), m_distribution(parallel::block(pg, 0)) {}
|
Chris@16
|
160
|
Chris@16
|
161 compressed_sparse_row_graph(vertices_size_type numverts,
|
Chris@16
|
162 const ProcessGroup& pg = ProcessGroup())
|
Chris@16
|
163 : m_process_group(pg), m_distribution(parallel::block(pg, 0)),
|
Chris@16
|
164 m_base(numverts)
|
Chris@16
|
165 {}
|
Chris@16
|
166
|
Chris@16
|
167 compressed_sparse_row_graph(vertices_size_type numverts,
|
Chris@16
|
168 const GraphProperty& prop,
|
Chris@16
|
169 const ProcessGroup& pg = ProcessGroup())
|
Chris@16
|
170 : m_process_group(pg), m_distribution(parallel::block(pg, 0)),
|
Chris@16
|
171 m_base(numverts)
|
Chris@16
|
172 {}
|
Chris@16
|
173
|
Chris@16
|
174 template <typename Distribution>
|
Chris@16
|
175 compressed_sparse_row_graph(vertices_size_type numverts,
|
Chris@16
|
176 const ProcessGroup& pg,
|
Chris@16
|
177 const Distribution& dist)
|
Chris@16
|
178 : m_process_group(pg), m_distribution(dist), m_base(numverts) {}
|
Chris@16
|
179
|
Chris@16
|
180 template <typename Distribution>
|
Chris@16
|
181 compressed_sparse_row_graph(vertices_size_type numverts,
|
Chris@16
|
182 const GraphProperty& prop,
|
Chris@16
|
183 const ProcessGroup& pg,
|
Chris@16
|
184 const Distribution& dist)
|
Chris@16
|
185 : m_process_group(pg), m_distribution(dist), m_base(numverts) {}
|
Chris@16
|
186
|
Chris@16
|
187 template <typename InputIterator>
|
Chris@16
|
188 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
189 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
190 vertices_size_type numverts,
|
Chris@16
|
191 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
192 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
193
|
Chris@16
|
194 template <typename InputIterator, typename Distribution>
|
Chris@16
|
195 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
196 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
197 vertices_size_type numverts,
|
Chris@16
|
198 const ProcessGroup& pg,
|
Chris@16
|
199 const Distribution& dist,
|
Chris@16
|
200 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
201
|
Chris@16
|
202 template <typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
203 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
204 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
205 EdgePropertyIterator ep_iter,
|
Chris@16
|
206 vertices_size_type numverts,
|
Chris@16
|
207 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
208 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
209
|
Chris@16
|
210 template <typename InputIterator, typename EdgePropertyIterator,
|
Chris@16
|
211 typename Distribution>
|
Chris@16
|
212 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
213 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
214 EdgePropertyIterator ep_iter,
|
Chris@16
|
215 vertices_size_type numverts,
|
Chris@16
|
216 const ProcessGroup& pg,
|
Chris@16
|
217 const Distribution& dist,
|
Chris@16
|
218 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
219
|
Chris@16
|
220 template <typename InputIterator>
|
Chris@16
|
221 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
222 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
223 vertices_size_type numverts,
|
Chris@16
|
224 edges_size_type numedges = 0,
|
Chris@16
|
225 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
226 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
227
|
Chris@16
|
228 template <typename InputIterator, typename Distribution>
|
Chris@16
|
229 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
230 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
231 vertices_size_type numverts,
|
Chris@16
|
232 const ProcessGroup& pg,
|
Chris@16
|
233 const Distribution& dist,
|
Chris@16
|
234 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
235
|
Chris@16
|
236 template <typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
237 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
238 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
239 EdgePropertyIterator ep_iter,
|
Chris@16
|
240 vertices_size_type numverts,
|
Chris@16
|
241 edges_size_type numedges = 0,
|
Chris@16
|
242 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
243 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
244
|
Chris@16
|
245 template <typename InputIterator, typename EdgePropertyIterator,
|
Chris@16
|
246 typename Distribution>
|
Chris@16
|
247 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
248 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
249 EdgePropertyIterator ep_iter,
|
Chris@16
|
250 vertices_size_type numverts,
|
Chris@16
|
251 const ProcessGroup& pg,
|
Chris@16
|
252 const Distribution& dist,
|
Chris@16
|
253 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
254
|
Chris@16
|
255 template <typename MultiPassInputIterator>
|
Chris@16
|
256 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
257 MultiPassInputIterator edge_begin,
|
Chris@16
|
258 MultiPassInputIterator edge_end,
|
Chris@16
|
259 vertices_size_type numverts,
|
Chris@16
|
260 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
261 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
262
|
Chris@16
|
263 template <typename MultiPassInputIterator, typename Distribution>
|
Chris@16
|
264 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
265 MultiPassInputIterator edge_begin,
|
Chris@16
|
266 MultiPassInputIterator edge_end,
|
Chris@16
|
267 vertices_size_type numverts,
|
Chris@16
|
268 const ProcessGroup& pg,
|
Chris@16
|
269 const Distribution& dist,
|
Chris@16
|
270 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
271
|
Chris@16
|
272 template <typename MultiPassInputIterator, typename EdgePropertyIterator>
|
Chris@16
|
273 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
274 MultiPassInputIterator edge_begin,
|
Chris@16
|
275 MultiPassInputIterator edge_end,
|
Chris@16
|
276 EdgePropertyIterator ep_iter,
|
Chris@16
|
277 vertices_size_type numverts,
|
Chris@16
|
278 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
279 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
280
|
Chris@16
|
281 template <typename MultiPassInputIterator, typename EdgePropertyIterator,
|
Chris@16
|
282 typename Distribution>
|
Chris@16
|
283 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
284 MultiPassInputIterator edge_begin,
|
Chris@16
|
285 MultiPassInputIterator edge_end,
|
Chris@16
|
286 EdgePropertyIterator ep_iter,
|
Chris@16
|
287 vertices_size_type numverts,
|
Chris@16
|
288 const ProcessGroup& pg,
|
Chris@16
|
289 const Distribution& dist,
|
Chris@16
|
290 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
291
|
Chris@16
|
292 template <typename Source>
|
Chris@16
|
293 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
294 std::vector<Source>& sources,
|
Chris@16
|
295 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
296 vertices_size_type numverts,
|
Chris@16
|
297 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
298 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
299
|
Chris@16
|
300 template <typename Distribution, typename Source>
|
Chris@16
|
301 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
302 std::vector<Source>& sources,
|
Chris@16
|
303 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
304 vertices_size_type numverts,
|
Chris@16
|
305 const ProcessGroup& pg,
|
Chris@16
|
306 const Distribution& dist,
|
Chris@16
|
307 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
308
|
Chris@16
|
309 template <typename Source>
|
Chris@16
|
310 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
311 std::vector<Source>& sources,
|
Chris@16
|
312 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
313 std::vector<edge_bundled>& edge_props,
|
Chris@16
|
314 vertices_size_type numverts,
|
Chris@16
|
315 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
316 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
317
|
Chris@16
|
318 template <typename Distribution, typename Source>
|
Chris@16
|
319 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
320 std::vector<Source>& sources,
|
Chris@16
|
321 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
322 std::vector<edge_bundled>& edge_props,
|
Chris@16
|
323 vertices_size_type numverts,
|
Chris@16
|
324 const ProcessGroup& pg,
|
Chris@16
|
325 const Distribution& dist,
|
Chris@16
|
326 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
327
|
Chris@16
|
328 template<typename InputIterator>
|
Chris@16
|
329 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
330 vertices_size_type numverts,
|
Chris@16
|
331 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
332 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
333
|
Chris@16
|
334 template<typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
335 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
336 EdgePropertyIterator ep_iter,
|
Chris@16
|
337 vertices_size_type numverts,
|
Chris@16
|
338 const ProcessGroup& pg = ProcessGroup(),
|
Chris@16
|
339 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
340
|
Chris@16
|
341 template<typename InputIterator, typename Distribution>
|
Chris@16
|
342 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
343 vertices_size_type numverts,
|
Chris@16
|
344 const ProcessGroup& pg,
|
Chris@16
|
345 const Distribution& dist,
|
Chris@16
|
346 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
347
|
Chris@16
|
348 template<typename InputIterator, typename EdgePropertyIterator,
|
Chris@16
|
349 typename Distribution>
|
Chris@16
|
350 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
351 EdgePropertyIterator ep_iter,
|
Chris@16
|
352 vertices_size_type numverts,
|
Chris@16
|
353 const ProcessGroup& pg,
|
Chris@16
|
354 const Distribution& dist,
|
Chris@16
|
355 const GraphProperty& prop = GraphProperty());
|
Chris@16
|
356
|
Chris@16
|
357 base_type& base() { return m_base; }
|
Chris@16
|
358 const base_type& base() const { return m_base; }
|
Chris@16
|
359
|
Chris@16
|
360 process_group_type process_group() const { return m_process_group.base(); }
|
Chris@16
|
361
|
Chris@16
|
362 distribution_type& distribution() { return m_distribution; }
|
Chris@16
|
363 const distribution_type& distribution() const { return m_distribution; }
|
Chris@16
|
364
|
Chris@16
|
365 // Directly access a vertex or edge bundle
|
Chris@16
|
366 vertex_bundled& operator[](vertex_descriptor v)
|
Chris@16
|
367 {
|
Chris@16
|
368 return get(vertex_bundle, *this, v);
|
Chris@16
|
369 }
|
Chris@16
|
370
|
Chris@16
|
371 const vertex_bundled& operator[](vertex_descriptor v) const
|
Chris@16
|
372 {
|
Chris@16
|
373 return get(vertex_bundle, *this, v);
|
Chris@16
|
374 }
|
Chris@16
|
375
|
Chris@16
|
376 edge_bundled& operator[](edge_descriptor e)
|
Chris@16
|
377 {
|
Chris@16
|
378 return get(edge_bundle, *this, e);
|
Chris@16
|
379 }
|
Chris@16
|
380
|
Chris@16
|
381 const edge_bundled& operator[](edge_descriptor e) const
|
Chris@16
|
382 {
|
Chris@16
|
383 return get(edge_bundle, *this, e);
|
Chris@16
|
384 }
|
Chris@16
|
385
|
Chris@16
|
386 // Create a vertex descriptor from a process ID and a local index.
|
Chris@16
|
387 vertex_descriptor
|
Chris@16
|
388 make_vertex_descriptor(process_id_type p, vertex_descriptor v) const
|
Chris@16
|
389 {
|
Chris@16
|
390 vertex_descriptor vertex_local_index_bits =
|
Chris@16
|
391 sizeof(vertex_descriptor) * CHAR_BIT - processor_bits;
|
Chris@16
|
392 return v | ((vertex_descriptor)p << vertex_local_index_bits);
|
Chris@16
|
393 }
|
Chris@16
|
394
|
Chris@16
|
395 // Convert a local vertex descriptor into a global vertex descriptor
|
Chris@16
|
396 vertex_descriptor local_to_global_vertex(vertex_descriptor v) const
|
Chris@16
|
397 {
|
Chris@16
|
398 return make_vertex_descriptor(process_id(m_process_group), v);
|
Chris@16
|
399 }
|
Chris@16
|
400
|
Chris@16
|
401 // Structural modification
|
Chris@16
|
402 vertex_descriptor add_vertex()
|
Chris@16
|
403 {
|
Chris@16
|
404 typename graph_traits<base_type>::vertex_descriptor v
|
Chris@16
|
405 = boost::add_vertex(m_base);
|
Chris@16
|
406
|
Chris@16
|
407 return make_vertex_descriptor(process_id(m_process_group), v);
|
Chris@16
|
408 }
|
Chris@16
|
409
|
Chris@16
|
410 vertex_descriptor add_vertex(const vertex_bundled& p)
|
Chris@16
|
411 {
|
Chris@16
|
412 typename graph_traits<base_type>::vertex_descriptor v
|
Chris@16
|
413 = boost::add_vertex(m_base, p);
|
Chris@16
|
414
|
Chris@16
|
415 return make_vertex_descriptor(process_id(m_process_group), v);
|
Chris@16
|
416 }
|
Chris@16
|
417
|
Chris@16
|
418 vertex_descriptor add_vertices(vertices_size_type count)
|
Chris@16
|
419 {
|
Chris@16
|
420 typename graph_traits<base_type>::vertex_descriptor v
|
Chris@16
|
421 = boost::add_vertices(count, m_base);
|
Chris@16
|
422
|
Chris@16
|
423 return make_vertex_descriptor(process_id(m_process_group), v);
|
Chris@16
|
424 }
|
Chris@16
|
425
|
Chris@16
|
426 template <typename InputIterator>
|
Chris@16
|
427 void
|
Chris@16
|
428 add_edges(InputIterator first, InputIterator last)
|
Chris@16
|
429 { boost::add_edges_global(first, last, get(vertex_local, *this), m_base); }
|
Chris@16
|
430
|
Chris@16
|
431 template <typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
432 void
|
Chris@16
|
433 add_edges(InputIterator first, InputIterator last,
|
Chris@16
|
434 EdgePropertyIterator ep_iter,
|
Chris@16
|
435 EdgePropertyIterator ep_iter_end)
|
Chris@16
|
436 { boost::add_edges_global(first, last, ep_iter, ep_iter_end,
|
Chris@16
|
437 get(vertex_local, *this), m_base); }
|
Chris@16
|
438
|
Chris@16
|
439 template <typename InputIterator>
|
Chris@16
|
440 void
|
Chris@16
|
441 add_edges_sorted(InputIterator first, InputIterator last)
|
Chris@16
|
442 { boost::add_edges_sorted_global(first, last,
|
Chris@16
|
443 get(vertex_local, *this), m_base); }
|
Chris@16
|
444
|
Chris@16
|
445 template <typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
446 void
|
Chris@16
|
447 add_edges_sorted(InputIterator first_sorted, InputIterator last_sorted,
|
Chris@16
|
448 EdgePropertyIterator ep_iter_sorted)
|
Chris@16
|
449 { boost::add_edges_sorted_global(first_sorted, last_sorted, ep_iter_sorted,
|
Chris@16
|
450 get(vertex_local, *this), m_base); }
|
Chris@16
|
451
|
Chris@16
|
452 protected:
|
Chris@16
|
453 ProcessGroup m_process_group;
|
Chris@16
|
454 distribution_type m_distribution;
|
Chris@16
|
455 base_type m_base;
|
Chris@16
|
456 };
|
Chris@16
|
457
|
Chris@16
|
458 /** @brief Helper macro containing the template parameters for the
|
Chris@16
|
459 * distributed CSR graph.
|
Chris@16
|
460 *
|
Chris@16
|
461 * This macro contains all of the template parameters needed for the
|
Chris@16
|
462 * distributed compressed_sparse_row graph type. It is used to reduce
|
Chris@16
|
463 * the amount of typing required to declare free functions for this
|
Chris@16
|
464 * graph type.
|
Chris@16
|
465 */
|
Chris@16
|
466 #define BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS \
|
Chris@16
|
467 typename VertexProperty, typename EdgeProperty, \
|
Chris@16
|
468 typename GraphProperty, typename ProcessGroup, typename InVertex, \
|
Chris@16
|
469 typename InDistribution, typename InEdgeIndex
|
Chris@16
|
470
|
Chris@16
|
471 /** @brief Helper macro containing the typical instantiation of the
|
Chris@16
|
472 * distributed CSR graph.
|
Chris@16
|
473 *
|
Chris@16
|
474 * This macro contains an instantiation of the distributed CSR graph
|
Chris@16
|
475 * type using the typical template parameters names (e.g., those
|
Chris@16
|
476 * provided by the macro @c
|
Chris@16
|
477 * BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS). It is used to reduce
|
Chris@16
|
478 * the amount of typing required to declare free functions for this
|
Chris@16
|
479 * graph type.
|
Chris@16
|
480 */
|
Chris@16
|
481 #define BOOST_DISTRIB_CSR_GRAPH_TYPE \
|
Chris@16
|
482 compressed_sparse_row_graph< \
|
Chris@16
|
483 directedS, VertexProperty, EdgeProperty, GraphProperty, \
|
Chris@16
|
484 distributedS<ProcessGroup, InVertex, InDistribution>, \
|
Chris@16
|
485 InEdgeIndex>
|
Chris@16
|
486
|
Chris@16
|
487 // -----------------------------------------------------------------
|
Chris@16
|
488 // Graph concept operations
|
Chris@16
|
489 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
490 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
491 BOOST_DISTRIB_CSR_GRAPH_TYPE::null_vertex()
|
Chris@16
|
492 {
|
Chris@16
|
493 return graph_traits<base_type>::null_vertex();
|
Chris@16
|
494 }
|
Chris@16
|
495
|
Chris@16
|
496 // -----------------------------------------------------------------
|
Chris@16
|
497 // Incidence Graph concept operations
|
Chris@16
|
498 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
499 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
500 source(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor e,
|
Chris@16
|
501 const BOOST_DISTRIB_CSR_GRAPH_TYPE&)
|
Chris@16
|
502 { return e.src; }
|
Chris@16
|
503
|
Chris@16
|
504 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
505 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
506 target(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor e,
|
Chris@16
|
507 const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
508 { return target(e, g.base()); }
|
Chris@16
|
509
|
Chris@16
|
510 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
511 inline std::pair<typename BOOST_DISTRIB_CSR_GRAPH_TYPE::out_edge_iterator,
|
Chris@16
|
512 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::out_edge_iterator>
|
Chris@16
|
513 out_edges(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor u,
|
Chris@16
|
514 const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
515 {
|
Chris@16
|
516 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type
|
Chris@16
|
517 edges_size_type;
|
Chris@16
|
518 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor ed;
|
Chris@16
|
519 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::out_edge_iterator it;
|
Chris@16
|
520 edges_size_type u_local = get(vertex_local, g, u);
|
Chris@16
|
521 edges_size_type u_row_start = g.base().m_forward.m_rowstart[u_local];
|
Chris@16
|
522 edges_size_type next_row_start = g.base().m_forward.m_rowstart[u_local + 1];
|
Chris@16
|
523 return std::make_pair(it(ed(u, u_row_start)),
|
Chris@16
|
524 it(ed(u, (std::max)(u_row_start, next_row_start))));
|
Chris@16
|
525 }
|
Chris@16
|
526
|
Chris@16
|
527 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
528 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::degree_size_type
|
Chris@16
|
529 out_degree(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor u,
|
Chris@16
|
530 const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
531 {
|
Chris@16
|
532 return out_degree(get(vertex_local, g, u), g.base());
|
Chris@16
|
533 }
|
Chris@16
|
534
|
Chris@16
|
535 // -----------------------------------------------------------------
|
Chris@16
|
536 // DistributedGraph concept requirements
|
Chris@16
|
537 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
538 void synchronize(const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
539 {
|
Chris@16
|
540 synchronize(g.process_group());
|
Chris@16
|
541 }
|
Chris@16
|
542
|
Chris@16
|
543 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
544 ProcessGroup
|
Chris@16
|
545 process_group(const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
546 { return g.process_group(); }
|
Chris@16
|
547
|
Chris@16
|
548
|
Chris@16
|
549 // -----------------------------------------------------------------
|
Chris@16
|
550 // Adjacency Graph concept requirements
|
Chris@16
|
551 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
552 inline std::pair<typename BOOST_DISTRIB_CSR_GRAPH_TYPE::adjacency_iterator,
|
Chris@16
|
553 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::adjacency_iterator>
|
Chris@16
|
554 adjacent_vertices(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor u,
|
Chris@16
|
555 const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
556 {
|
Chris@16
|
557 return adjacent_vertices(get(vertex_local, g, u), g.base());
|
Chris@16
|
558 }
|
Chris@16
|
559
|
Chris@16
|
560 // -----------------------------------------------------------------
|
Chris@16
|
561 // Distributed Vertex List Graph concept operations
|
Chris@16
|
562 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
563 class BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_iterator
|
Chris@16
|
564 : public iterator_adaptor<vertex_iterator,
|
Chris@16
|
565 counting_iterator<Vertex>,
|
Chris@16
|
566 Vertex,
|
Chris@16
|
567 random_access_traversal_tag,
|
Chris@16
|
568 Vertex>
|
Chris@16
|
569 {
|
Chris@16
|
570 typedef iterator_adaptor<vertex_iterator,
|
Chris@16
|
571 counting_iterator<Vertex>,
|
Chris@16
|
572 Vertex,
|
Chris@16
|
573 random_access_traversal_tag,
|
Chris@16
|
574 Vertex> inherited;
|
Chris@16
|
575 public:
|
Chris@16
|
576 vertex_iterator() {}
|
Chris@16
|
577
|
Chris@16
|
578 explicit vertex_iterator(Vertex v, const self_type* graph)
|
Chris@16
|
579 : inherited(counting_iterator<Vertex>(v)), graph(graph) { }
|
Chris@16
|
580
|
Chris@16
|
581 Vertex dereference() const
|
Chris@16
|
582 {
|
Chris@16
|
583 return graph->local_to_global_vertex(*(this->base_reference()));
|
Chris@16
|
584 }
|
Chris@16
|
585
|
Chris@16
|
586 friend class iterator_core_access;
|
Chris@16
|
587
|
Chris@16
|
588 private:
|
Chris@16
|
589 const self_type* graph;
|
Chris@16
|
590 };
|
Chris@16
|
591
|
Chris@16
|
592 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
593 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::degree_size_type
|
Chris@16
|
594 num_vertices(const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
595 {
|
Chris@16
|
596 return num_vertices(g.base());
|
Chris@16
|
597 }
|
Chris@16
|
598
|
Chris@16
|
599 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
600 inline std::pair<typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_iterator,
|
Chris@16
|
601 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_iterator>
|
Chris@16
|
602 vertices(const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
603 {
|
Chris@16
|
604 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_iterator
|
Chris@16
|
605 vertex_iterator;
|
Chris@16
|
606 return std::make_pair(vertex_iterator(0, &g),
|
Chris@16
|
607 vertex_iterator(num_vertices(g), &g));
|
Chris@16
|
608 }
|
Chris@16
|
609
|
Chris@16
|
610 // -----------------------------------------------------------------
|
Chris@16
|
611 // Distributed Edge List Graph concept operations
|
Chris@16
|
612 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
613 class BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_iterator
|
Chris@16
|
614 {
|
Chris@16
|
615 public:
|
Chris@16
|
616 typedef std::forward_iterator_tag iterator_category;
|
Chris@16
|
617 typedef edge_descriptor value_type;
|
Chris@16
|
618
|
Chris@16
|
619 typedef const edge_descriptor* pointer;
|
Chris@16
|
620
|
Chris@16
|
621 typedef edge_descriptor reference;
|
Chris@16
|
622 typedef typename int_t<CHAR_BIT * sizeof(EdgeIndex)>::fast difference_type;
|
Chris@16
|
623
|
Chris@16
|
624 edge_iterator() : graph(0), current_edge(), end_of_this_vertex(0) {}
|
Chris@16
|
625
|
Chris@16
|
626 edge_iterator(const compressed_sparse_row_graph& graph,
|
Chris@16
|
627 edge_descriptor current_edge,
|
Chris@16
|
628 EdgeIndex end_of_this_vertex)
|
Chris@16
|
629 : graph(&graph), local_src(current_edge.src), current_edge(current_edge),
|
Chris@16
|
630 end_of_this_vertex(end_of_this_vertex)
|
Chris@16
|
631 {
|
Chris@16
|
632 // The edge that comes in has a local source vertex. Make it global.
|
Chris@16
|
633 current_edge.src = graph.local_to_global_vertex(current_edge.src);
|
Chris@16
|
634 }
|
Chris@16
|
635
|
Chris@16
|
636 // From InputIterator
|
Chris@16
|
637 reference operator*() const { return current_edge; }
|
Chris@16
|
638 pointer operator->() const { return ¤t_edge; }
|
Chris@16
|
639
|
Chris@16
|
640 bool operator==(const edge_iterator& o) const {
|
Chris@16
|
641 return current_edge == o.current_edge;
|
Chris@16
|
642 }
|
Chris@16
|
643 bool operator!=(const edge_iterator& o) const {
|
Chris@16
|
644 return current_edge != o.current_edge;
|
Chris@16
|
645 }
|
Chris@16
|
646
|
Chris@16
|
647 edge_iterator& operator++()
|
Chris@16
|
648 {
|
Chris@16
|
649 ++current_edge.idx;
|
Chris@16
|
650 while (current_edge.idx == end_of_this_vertex && local_src < num_vertices(*graph)-1) {
|
Chris@16
|
651 ++local_src;
|
Chris@16
|
652 current_edge.src = graph->local_to_global_vertex(local_src);
|
Chris@16
|
653 end_of_this_vertex = graph->base().m_forward.m_rowstart[local_src + 1];
|
Chris@16
|
654 }
|
Chris@16
|
655 return *this;
|
Chris@16
|
656 }
|
Chris@16
|
657
|
Chris@16
|
658 edge_iterator operator++(int) {
|
Chris@16
|
659 edge_iterator temp = *this;
|
Chris@16
|
660 ++*this;
|
Chris@16
|
661 return temp;
|
Chris@16
|
662 }
|
Chris@16
|
663
|
Chris@16
|
664 private:
|
Chris@16
|
665 const compressed_sparse_row_graph* graph;
|
Chris@16
|
666 EdgeIndex local_src;
|
Chris@16
|
667 edge_descriptor current_edge;
|
Chris@16
|
668 EdgeIndex end_of_this_vertex;
|
Chris@16
|
669 };
|
Chris@16
|
670
|
Chris@16
|
671 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
672 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type
|
Chris@16
|
673 num_edges(const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
674 {
|
Chris@16
|
675 return g.base().m_forward.m_column.size();
|
Chris@16
|
676 }
|
Chris@16
|
677
|
Chris@16
|
678 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
679 std::pair<typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_iterator,
|
Chris@16
|
680 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_iterator>
|
Chris@16
|
681 edges(const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
682 {
|
Chris@16
|
683 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor Vertex;
|
Chris@16
|
684 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_iterator ei;
|
Chris@16
|
685 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor edgedesc;
|
Chris@16
|
686 if (g.base().m_forward.m_rowstart.size() == 1 ||
|
Chris@16
|
687 g.base().m_forward.m_column.empty()) {
|
Chris@16
|
688 return std::make_pair(ei(), ei());
|
Chris@16
|
689 } else {
|
Chris@16
|
690 // Find the first vertex that has outgoing edges
|
Chris@16
|
691 Vertex src = 0;
|
Chris@16
|
692 while (g.base().m_forward.m_rowstart[src + 1] == 0) ++src;
|
Chris@16
|
693 return std::make_pair(ei(g, edgedesc(src, 0), g.base().m_forward.m_rowstart[src + 1]),
|
Chris@16
|
694 ei(g, edgedesc(num_vertices(g), g.base().m_forward.m_column.size()), 0));
|
Chris@16
|
695 }
|
Chris@16
|
696 }
|
Chris@16
|
697
|
Chris@16
|
698 // -----------------------------------------------------------------
|
Chris@16
|
699 // Graph constructors
|
Chris@16
|
700
|
Chris@16
|
701 // Returns true if a vertex belongs to a process according to a distribution
|
Chris@16
|
702 template <typename OwnerMap, typename ProcessId>
|
Chris@16
|
703 struct local_vertex {
|
Chris@16
|
704
|
Chris@16
|
705 local_vertex(OwnerMap owner, ProcessId id)
|
Chris@16
|
706 : owner(owner), id(id) {}
|
Chris@16
|
707
|
Chris@16
|
708 template <typename Vertex>
|
Chris@16
|
709 bool operator()(Vertex x)
|
Chris@16
|
710 { return get(owner, x) == id; }
|
Chris@16
|
711
|
Chris@16
|
712 template <typename Vertex>
|
Chris@16
|
713 bool operator()(Vertex x) const
|
Chris@16
|
714 { return get(owner, x) == id; }
|
Chris@16
|
715
|
Chris@16
|
716 private:
|
Chris@16
|
717 OwnerMap owner;
|
Chris@16
|
718 ProcessId id;
|
Chris@16
|
719 };
|
Chris@16
|
720
|
Chris@16
|
721 // Returns true if a vertex belongs to a process according to a distribution
|
Chris@16
|
722 template <typename OwnerMap, typename ProcessId>
|
Chris@16
|
723 struct local_edge {
|
Chris@16
|
724
|
Chris@16
|
725 local_edge(OwnerMap owner, ProcessId id)
|
Chris@16
|
726 : owner(owner), id(id) {}
|
Chris@16
|
727
|
Chris@16
|
728 template <typename Vertex>
|
Chris@16
|
729 bool operator()(std::pair<Vertex, Vertex>& x)
|
Chris@16
|
730 { return get(owner, x.first) == id; }
|
Chris@16
|
731
|
Chris@16
|
732 template <typename Vertex>
|
Chris@16
|
733 bool operator()(const std::pair<Vertex, Vertex>& x) const
|
Chris@16
|
734 { return get(owner, x.first) == id; }
|
Chris@16
|
735
|
Chris@16
|
736 private:
|
Chris@16
|
737 OwnerMap owner;
|
Chris@16
|
738 ProcessId id;
|
Chris@16
|
739 };
|
Chris@16
|
740
|
Chris@16
|
741 // Turns an index iterator into a vertex iterator
|
Chris@16
|
742 template<typename IndexIterator, typename Graph>
|
Chris@16
|
743 class index_to_vertex_iterator {
|
Chris@16
|
744
|
Chris@16
|
745 public:
|
Chris@16
|
746 typedef std::input_iterator_tag iterator_category;
|
Chris@16
|
747 typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
|
Chris@16
|
748 typedef std::pair<Vertex, Vertex> value_type;
|
Chris@16
|
749 typedef const value_type& reference;
|
Chris@16
|
750 typedef const value_type* pointer;
|
Chris@16
|
751 typedef void difference_type;
|
Chris@16
|
752
|
Chris@16
|
753 index_to_vertex_iterator(IndexIterator index,
|
Chris@16
|
754 const Graph& g)
|
Chris@16
|
755 : index(index), g(g), current(to_edge(*index)) {}
|
Chris@16
|
756
|
Chris@16
|
757 reference operator*() { current = to_edge(*index); return current; }
|
Chris@16
|
758 pointer operator->() { current = to_edge(*index); return ¤t; }
|
Chris@16
|
759
|
Chris@16
|
760 index_to_vertex_iterator& operator++()
|
Chris@16
|
761 {
|
Chris@16
|
762 ++index;
|
Chris@16
|
763 return *this;
|
Chris@16
|
764 }
|
Chris@16
|
765
|
Chris@16
|
766 index_to_vertex_iterator operator++(int)
|
Chris@16
|
767 {
|
Chris@16
|
768 index_to_vertex_iterator temp(*this);
|
Chris@16
|
769 ++(*this);
|
Chris@16
|
770 return temp;
|
Chris@16
|
771 }
|
Chris@16
|
772
|
Chris@16
|
773 bool operator==(const index_to_vertex_iterator& other) const
|
Chris@16
|
774 { return index == other.index; }
|
Chris@16
|
775
|
Chris@16
|
776 bool operator!=(const index_to_vertex_iterator& other) const
|
Chris@16
|
777 { return !(*this == other); }
|
Chris@16
|
778
|
Chris@16
|
779 private:
|
Chris@16
|
780 value_type to_edge(const typename std::iterator_traits<IndexIterator>::value_type& x)
|
Chris@16
|
781 { return std::make_pair(vertex(x.first, g), vertex(x.second, g)); }
|
Chris@16
|
782
|
Chris@16
|
783 IndexIterator index;
|
Chris@16
|
784 const Graph& g;
|
Chris@16
|
785 value_type current;
|
Chris@16
|
786 };
|
Chris@16
|
787
|
Chris@16
|
788 template <typename Distribution, typename Graph>
|
Chris@16
|
789 struct index_to_vertex_func {
|
Chris@16
|
790
|
Chris@16
|
791 typedef typename boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
|
Chris@16
|
792 typedef typename boost::graph_traits<Graph>::vertices_size_type vertices_size_type;
|
Chris@16
|
793 typedef std::pair<vertex_descriptor, vertex_descriptor> result_type;
|
Chris@16
|
794 typedef std::pair<vertices_size_type, vertices_size_type> base_iterator_type;
|
Chris@16
|
795
|
Chris@16
|
796 index_to_vertex_func(const Distribution& dist, const Graph& g)
|
Chris@16
|
797 : dist(dist), g(g) {}
|
Chris@16
|
798
|
Chris@16
|
799
|
Chris@16
|
800 result_type operator()(const base_iterator_type& p) const
|
Chris@16
|
801 {
|
Chris@16
|
802 return std::make_pair(vertex(p.first, g), vertex(p.second, g));
|
Chris@16
|
803 }
|
Chris@16
|
804
|
Chris@16
|
805 private:
|
Chris@16
|
806 const Distribution& dist;
|
Chris@16
|
807 const Graph& g;
|
Chris@16
|
808 };
|
Chris@16
|
809
|
Chris@16
|
810 // NGE: This method only works with iterators that have a difference_type,
|
Chris@16
|
811 // the index_to_vertex_iterator class above is retained for compatibility
|
Chris@16
|
812 // with BGL generators which have no difference_type
|
Chris@16
|
813 template <typename IndexIterator, typename Distribution, typename Graph>
|
Chris@16
|
814 boost::transform_iterator<index_to_vertex_func<Distribution, Graph>, IndexIterator>
|
Chris@16
|
815 make_index_to_vertex_iterator(IndexIterator it, const Distribution& dist,
|
Chris@16
|
816 const Graph& g) {
|
Chris@16
|
817 return boost::make_transform_iterator(
|
Chris@16
|
818 it, index_to_vertex_func<Distribution, Graph>(dist, g));
|
Chris@16
|
819 }
|
Chris@16
|
820
|
Chris@16
|
821 // Forward declaration of csr_vertex_owner_map
|
Chris@16
|
822 template<typename ProcessID, typename Key> class csr_vertex_owner_map;
|
Chris@16
|
823
|
Chris@16
|
824 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
825 template<typename InputIterator>
|
Chris@16
|
826 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
827 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
828 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
829 vertices_size_type numverts,
|
Chris@16
|
830 const ProcessGroup& pg,
|
Chris@16
|
831 const GraphProperty& prop)
|
Chris@16
|
832 : m_process_group(pg),
|
Chris@16
|
833 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
834 m_base(edges_are_unsorted_global,
|
Chris@16
|
835 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
836 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
837 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
838 get(vertex_local, *this),
|
Chris@16
|
839 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
840 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
841 prop)
|
Chris@16
|
842 { }
|
Chris@16
|
843
|
Chris@16
|
844 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
845 template <typename InputIterator, typename Distribution>
|
Chris@16
|
846 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
847 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
848 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
849 vertices_size_type numverts,
|
Chris@16
|
850 const ProcessGroup& pg,
|
Chris@16
|
851 const Distribution& dist,
|
Chris@16
|
852 const GraphProperty& prop)
|
Chris@16
|
853 : m_process_group(pg),
|
Chris@16
|
854 m_distribution(dist),
|
Chris@16
|
855 m_base(edges_are_unsorted_global,
|
Chris@16
|
856 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
857 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
858 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
859 get(vertex_local, *this),
|
Chris@16
|
860 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
861 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
862 prop)
|
Chris@16
|
863 { }
|
Chris@16
|
864
|
Chris@16
|
865 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
866 template<typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
867 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
868 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
869 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
870 EdgePropertyIterator ep_iter,
|
Chris@16
|
871 vertices_size_type numverts,
|
Chris@16
|
872 const ProcessGroup& pg,
|
Chris@16
|
873 const GraphProperty& prop)
|
Chris@16
|
874 : m_process_group(pg),
|
Chris@16
|
875 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
876 m_base(edges_are_unsorted_global,
|
Chris@16
|
877 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
878 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
879 ep_iter,
|
Chris@16
|
880 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
881 get(vertex_local, *this),
|
Chris@16
|
882 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
883 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
884 prop)
|
Chris@16
|
885 { }
|
Chris@16
|
886
|
Chris@16
|
887 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
888 template <typename InputIterator, typename EdgePropertyIterator,
|
Chris@16
|
889 typename Distribution>
|
Chris@16
|
890 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
891 compressed_sparse_row_graph(edges_are_unsorted_t,
|
Chris@16
|
892 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
893 EdgePropertyIterator ep_iter,
|
Chris@16
|
894 vertices_size_type numverts,
|
Chris@16
|
895 const ProcessGroup& pg,
|
Chris@16
|
896 const Distribution& dist,
|
Chris@16
|
897 const GraphProperty& prop)
|
Chris@16
|
898 : m_process_group(pg),
|
Chris@16
|
899 m_distribution(dist),
|
Chris@16
|
900 m_base(edges_are_unsorted_global,
|
Chris@16
|
901 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
902 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
903 ep_iter,
|
Chris@16
|
904 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
905 get(vertex_local, *this),
|
Chris@16
|
906 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
907 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
908 prop)
|
Chris@16
|
909 { }
|
Chris@16
|
910
|
Chris@16
|
911 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
912 template<typename InputIterator>
|
Chris@16
|
913 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
914 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
915 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
916 vertices_size_type numverts,
|
Chris@16
|
917 edges_size_type numedges, // This is not used as there is no appropriate BGL ctor
|
Chris@16
|
918 const ProcessGroup& pg,
|
Chris@16
|
919 const GraphProperty& prop)
|
Chris@16
|
920 : m_process_group(pg),
|
Chris@16
|
921 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
922 m_base(edges_are_sorted_global,
|
Chris@16
|
923 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
924 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
925 get(vertex_local, *this),
|
Chris@16
|
926 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
927 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
928 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
929 prop)
|
Chris@16
|
930 { }
|
Chris@16
|
931
|
Chris@16
|
932 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
933 template <typename InputIterator, typename Distribution>
|
Chris@16
|
934 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
935 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
936 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
937 vertices_size_type numverts,
|
Chris@16
|
938 const ProcessGroup& pg,
|
Chris@16
|
939 const Distribution& dist,
|
Chris@16
|
940 const GraphProperty& prop)
|
Chris@16
|
941 : m_process_group(pg),
|
Chris@16
|
942 m_distribution(dist),
|
Chris@16
|
943 m_base(edges_are_sorted_global,
|
Chris@16
|
944 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
945 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
946 get(vertex_local, *this),
|
Chris@16
|
947 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
948 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
949 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
950 prop)
|
Chris@16
|
951 { }
|
Chris@16
|
952
|
Chris@16
|
953 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
954 template<typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
955 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
956 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
957 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
958 EdgePropertyIterator ep_iter,
|
Chris@16
|
959 vertices_size_type numverts,
|
Chris@16
|
960 edges_size_type numedges, // This is not used as there is no appropriate BGL ctor
|
Chris@16
|
961 const ProcessGroup& pg,
|
Chris@16
|
962 const GraphProperty& prop)
|
Chris@16
|
963 : m_process_group(pg),
|
Chris@16
|
964 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
965 m_base(edges_are_sorted_global,
|
Chris@16
|
966 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
967 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
968 ep_iter,
|
Chris@16
|
969 get(vertex_local, *this),
|
Chris@16
|
970 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
971 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
972 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
973 prop)
|
Chris@16
|
974 { }
|
Chris@16
|
975
|
Chris@16
|
976 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
977 template<typename InputIterator, typename EdgePropertyIterator,
|
Chris@16
|
978 typename Distribution>
|
Chris@16
|
979 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
980 compressed_sparse_row_graph(edges_are_sorted_t,
|
Chris@16
|
981 InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
982 EdgePropertyIterator ep_iter,
|
Chris@16
|
983 vertices_size_type numverts,
|
Chris@16
|
984 const ProcessGroup& pg,
|
Chris@16
|
985 const Distribution& dist,
|
Chris@16
|
986 const GraphProperty& prop)
|
Chris@16
|
987 : m_process_group(pg),
|
Chris@16
|
988 m_distribution(dist),
|
Chris@16
|
989 m_base(edges_are_sorted_global,
|
Chris@16
|
990 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
991 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
992 ep_iter,
|
Chris@16
|
993 get(vertex_local, *this),
|
Chris@16
|
994 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
995 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
996 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
997 prop)
|
Chris@16
|
998 { }
|
Chris@16
|
999
|
Chris@16
|
1000 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1001 template<typename MultiPassInputIterator>
|
Chris@16
|
1002 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1003 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
1004 MultiPassInputIterator edge_begin,
|
Chris@16
|
1005 MultiPassInputIterator edge_end,
|
Chris@16
|
1006 vertices_size_type numverts,
|
Chris@16
|
1007 const ProcessGroup& pg,
|
Chris@16
|
1008 const GraphProperty& prop)
|
Chris@16
|
1009 : m_process_group(pg),
|
Chris@16
|
1010 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
1011 m_base(edges_are_unsorted_multi_pass_global,
|
Chris@16
|
1012 make_index_to_vertex_iterator(edge_begin, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1013 make_index_to_vertex_iterator(edge_end, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1014 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1015 get(vertex_local, *this),
|
Chris@16
|
1016 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1017 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1018 prop)
|
Chris@16
|
1019 { }
|
Chris@16
|
1020
|
Chris@16
|
1021 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1022 template <typename MultiPassInputIterator, typename Distribution>
|
Chris@16
|
1023 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1024 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
1025 MultiPassInputIterator edge_begin,
|
Chris@16
|
1026 MultiPassInputIterator edge_end,
|
Chris@16
|
1027 vertices_size_type numverts,
|
Chris@16
|
1028 const ProcessGroup& pg,
|
Chris@16
|
1029 const Distribution& dist,
|
Chris@16
|
1030 const GraphProperty& prop)
|
Chris@16
|
1031 : m_process_group(pg),
|
Chris@16
|
1032 m_distribution(dist),
|
Chris@16
|
1033 m_base(edges_are_unsorted_multi_pass_global,
|
Chris@16
|
1034 make_index_to_vertex_iterator(edge_begin, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1035 make_index_to_vertex_iterator(edge_end, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1036 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1037 get(vertex_local, *this),
|
Chris@16
|
1038 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1039 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1040 prop)
|
Chris@16
|
1041 { }
|
Chris@16
|
1042
|
Chris@16
|
1043
|
Chris@16
|
1044 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1045 template<typename MultiPassInputIterator, typename EdgePropertyIterator>
|
Chris@16
|
1046 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1047 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
1048 MultiPassInputIterator edge_begin,
|
Chris@16
|
1049 MultiPassInputIterator edge_end,
|
Chris@16
|
1050 EdgePropertyIterator ep_iter,
|
Chris@16
|
1051 vertices_size_type numverts,
|
Chris@16
|
1052 const ProcessGroup& pg,
|
Chris@16
|
1053 const GraphProperty& prop)
|
Chris@16
|
1054 : m_process_group(pg),
|
Chris@16
|
1055 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
1056 m_base(edges_are_unsorted_multi_pass_global,
|
Chris@16
|
1057 make_index_to_vertex_iterator(edge_begin, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1058 make_index_to_vertex_iterator(edge_end, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1059 ep_iter,
|
Chris@16
|
1060 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1061 get(vertex_local, *this),
|
Chris@16
|
1062 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1063 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1064 prop)
|
Chris@16
|
1065 { }
|
Chris@16
|
1066
|
Chris@16
|
1067 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1068 template <typename MultiPassInputIterator, typename EdgePropertyIterator,
|
Chris@16
|
1069 typename Distribution>
|
Chris@16
|
1070 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1071 compressed_sparse_row_graph(edges_are_unsorted_multi_pass_t,
|
Chris@16
|
1072 MultiPassInputIterator edge_begin,
|
Chris@16
|
1073 MultiPassInputIterator edge_end,
|
Chris@16
|
1074 EdgePropertyIterator ep_iter,
|
Chris@16
|
1075 vertices_size_type numverts,
|
Chris@16
|
1076 const ProcessGroup& pg,
|
Chris@16
|
1077 const Distribution& dist,
|
Chris@16
|
1078 const GraphProperty& prop)
|
Chris@16
|
1079 : m_process_group(pg),
|
Chris@16
|
1080 m_distribution(dist),
|
Chris@16
|
1081 m_base(edges_are_unsorted_multi_pass_global,
|
Chris@16
|
1082 make_index_to_vertex_iterator(edge_begin, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1083 make_index_to_vertex_iterator(edge_end, parallel::block(m_process_group, numverts), *this),
|
Chris@16
|
1084 ep_iter,
|
Chris@16
|
1085 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1086 get(vertex_local, *this),
|
Chris@16
|
1087 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1088 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1089 prop)
|
Chris@16
|
1090 { }
|
Chris@16
|
1091
|
Chris@16
|
1092 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1093 template<typename Source>
|
Chris@16
|
1094 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1095 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
1096 std::vector<Source>& sources,
|
Chris@16
|
1097 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
1098 vertices_size_type numverts,
|
Chris@16
|
1099 const ProcessGroup& pg,
|
Chris@16
|
1100 const GraphProperty& prop)
|
Chris@16
|
1101 : m_process_group(pg),
|
Chris@16
|
1102 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
1103 m_base(m_distribution.block_size(process_id(m_process_group), numverts))
|
Chris@16
|
1104 {
|
Chris@16
|
1105 // Convert linear indices to global indices
|
Chris@16
|
1106 for (edges_size_type i = 0; i < sources.size(); ++i) {
|
Chris@16
|
1107 sources[i] = m_distribution.local(sources[i]);
|
Chris@16
|
1108 targets[i] = make_vertex_descriptor(m_distribution(targets[i]),
|
Chris@16
|
1109 m_distribution.local(targets[i]));
|
Chris@16
|
1110 }
|
Chris@16
|
1111
|
Chris@16
|
1112 m_base.assign_sources_and_targets_global(
|
Chris@16
|
1113 sources, targets, m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1114 identity_property_map());
|
Chris@16
|
1115
|
Chris@16
|
1116 // TODO: set property on m_base?
|
Chris@16
|
1117 }
|
Chris@16
|
1118
|
Chris@16
|
1119 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1120 template <typename Distribution, typename Source>
|
Chris@16
|
1121 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1122 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
1123 std::vector<Source>& sources,
|
Chris@16
|
1124 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
1125 vertices_size_type numverts,
|
Chris@16
|
1126 const ProcessGroup& pg,
|
Chris@16
|
1127 const Distribution& dist,
|
Chris@16
|
1128 const GraphProperty& prop)
|
Chris@16
|
1129 : m_process_group(pg),
|
Chris@16
|
1130 m_distribution(dist),
|
Chris@16
|
1131 m_base(m_distribution.block_size(process_id(m_process_group), numverts))
|
Chris@16
|
1132 {
|
Chris@16
|
1133 // Convert linear indices to global indices
|
Chris@16
|
1134 for (edges_size_type i = 0; i < sources.size(); ++i) {
|
Chris@16
|
1135 sources[i] = m_distribution.local(sources[i]);
|
Chris@16
|
1136 targets[i] = make_vertex_descriptor(m_distribution(targets[i]),
|
Chris@16
|
1137 m_distribution.local(targets[i]));
|
Chris@16
|
1138 }
|
Chris@16
|
1139
|
Chris@16
|
1140 m_base.assign_sources_and_targets_global(
|
Chris@16
|
1141 sources, targets, m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1142 identity_property_map());
|
Chris@16
|
1143
|
Chris@16
|
1144 // TODO: set property on m_base?
|
Chris@16
|
1145 }
|
Chris@16
|
1146
|
Chris@16
|
1147 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1148 template<typename Source>
|
Chris@16
|
1149 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1150 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
1151 std::vector<Source>& sources,
|
Chris@16
|
1152 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
1153 std::vector<edge_bundled>& edge_props,
|
Chris@16
|
1154 vertices_size_type numverts,
|
Chris@16
|
1155 const ProcessGroup& pg,
|
Chris@16
|
1156 const GraphProperty& prop)
|
Chris@16
|
1157 : m_process_group(pg),
|
Chris@16
|
1158 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
1159 m_base(m_distribution.block_size(process_id(m_process_group), numverts))
|
Chris@16
|
1160 {
|
Chris@16
|
1161 // Convert linear indices to global indices
|
Chris@16
|
1162 for (edges_size_type i = 0; i < sources.size(); ++i) {
|
Chris@16
|
1163 sources[i] = m_distribution.local(sources[i]);
|
Chris@16
|
1164 targets[i] = make_vertex_descriptor(m_distribution(targets[i]),
|
Chris@16
|
1165 m_distribution.local(targets[i]));
|
Chris@16
|
1166 }
|
Chris@16
|
1167
|
Chris@16
|
1168 m_base.assign_sources_and_targets_global(
|
Chris@16
|
1169 sources, targets, edge_props,
|
Chris@16
|
1170 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1171 identity_property_map());
|
Chris@16
|
1172
|
Chris@16
|
1173 // TODO: set property on m_base?
|
Chris@16
|
1174 }
|
Chris@16
|
1175
|
Chris@16
|
1176 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1177 template <typename Distribution, typename Source>
|
Chris@16
|
1178 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1179 compressed_sparse_row_graph(distributed_construct_inplace_from_sources_and_targets_t,
|
Chris@16
|
1180 std::vector<Source>& sources,
|
Chris@16
|
1181 std::vector<vertex_descriptor>& targets,
|
Chris@16
|
1182 std::vector<edge_bundled>& edge_props,
|
Chris@16
|
1183 vertices_size_type numverts,
|
Chris@16
|
1184 const ProcessGroup& pg,
|
Chris@16
|
1185 const Distribution& dist,
|
Chris@16
|
1186 const GraphProperty& prop)
|
Chris@16
|
1187 : m_process_group(pg),
|
Chris@16
|
1188 m_distribution(dist),
|
Chris@16
|
1189 m_base(m_distribution.block_size(process_id(m_process_group), numverts))
|
Chris@16
|
1190 {
|
Chris@16
|
1191 // Convert linear indices to global indices
|
Chris@16
|
1192 for (edges_size_type i = 0; i < sources.size(); ++i) {
|
Chris@16
|
1193 sources[i] = m_distribution.local(sources[i]);
|
Chris@16
|
1194 targets[i] = make_vertex_descriptor(m_distribution(targets[i]),
|
Chris@16
|
1195 m_distribution.local(targets[i]));
|
Chris@16
|
1196 }
|
Chris@16
|
1197
|
Chris@16
|
1198 m_base.assign_sources_and_targets_global(
|
Chris@16
|
1199 sources, targets, edge_props,
|
Chris@16
|
1200 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1201 identity_property_map());
|
Chris@16
|
1202
|
Chris@16
|
1203 // TODO: set property on m_base?
|
Chris@16
|
1204 }
|
Chris@16
|
1205
|
Chris@16
|
1206 //
|
Chris@16
|
1207 // Old (untagged) ctors, these default to the unsorted sequential ctors
|
Chris@16
|
1208 //
|
Chris@16
|
1209 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1210 template<typename InputIterator>
|
Chris@16
|
1211 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1212 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
1213 vertices_size_type numverts,
|
Chris@16
|
1214 const ProcessGroup& pg,
|
Chris@16
|
1215 const GraphProperty& prop)
|
Chris@16
|
1216 : m_process_group(pg),
|
Chris@16
|
1217 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
1218 m_base(edges_are_unsorted_global,
|
Chris@16
|
1219 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
1220 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
1221 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1222 get(vertex_local, *this),
|
Chris@16
|
1223 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1224 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1225 prop)
|
Chris@16
|
1226
|
Chris@16
|
1227 {
|
Chris@16
|
1228 }
|
Chris@16
|
1229
|
Chris@16
|
1230 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1231 template<typename InputIterator, typename EdgePropertyIterator>
|
Chris@16
|
1232 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1233 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
1234 EdgePropertyIterator ep_iter,
|
Chris@16
|
1235 vertices_size_type numverts,
|
Chris@16
|
1236 const ProcessGroup& pg,
|
Chris@16
|
1237 const GraphProperty& prop)
|
Chris@16
|
1238 : m_process_group(pg),
|
Chris@16
|
1239
|
Chris@16
|
1240 m_distribution(parallel::block(m_process_group, numverts)),
|
Chris@16
|
1241 m_base(edges_are_unsorted_global,
|
Chris@16
|
1242 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
1243 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
1244 ep_iter,
|
Chris@16
|
1245 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1246 get(vertex_local, *this),
|
Chris@16
|
1247 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1248 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1249 prop)
|
Chris@16
|
1250 {
|
Chris@16
|
1251 }
|
Chris@16
|
1252
|
Chris@16
|
1253 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1254 template<typename InputIterator, typename Distribution>
|
Chris@16
|
1255 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1256 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
1257 vertices_size_type numverts,
|
Chris@16
|
1258 const ProcessGroup& pg,
|
Chris@16
|
1259 const Distribution& dist,
|
Chris@16
|
1260 const GraphProperty& prop)
|
Chris@16
|
1261 : m_process_group(pg),
|
Chris@16
|
1262 m_distribution(dist),
|
Chris@16
|
1263 m_base(edges_are_unsorted_global,
|
Chris@16
|
1264 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
1265 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
1266 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1267 get(vertex_local, *this),
|
Chris@16
|
1268 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1269 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1270 prop)
|
Chris@16
|
1271 {
|
Chris@16
|
1272 }
|
Chris@16
|
1273
|
Chris@16
|
1274 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1275 template<typename InputIterator, typename EdgePropertyIterator,
|
Chris@16
|
1276 typename Distribution>
|
Chris@16
|
1277 BOOST_DISTRIB_CSR_GRAPH_TYPE::
|
Chris@16
|
1278 compressed_sparse_row_graph(InputIterator edge_begin, InputIterator edge_end,
|
Chris@16
|
1279 EdgePropertyIterator ep_iter,
|
Chris@16
|
1280 vertices_size_type numverts,
|
Chris@16
|
1281 const ProcessGroup& pg,
|
Chris@16
|
1282 const Distribution& dist,
|
Chris@16
|
1283 const GraphProperty& prop)
|
Chris@16
|
1284 : m_process_group(pg),
|
Chris@16
|
1285 m_distribution(dist),
|
Chris@16
|
1286 m_base(edges_are_unsorted_global,
|
Chris@16
|
1287 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_begin, *this),
|
Chris@16
|
1288 index_to_vertex_iterator<InputIterator, BOOST_DISTRIB_CSR_GRAPH_TYPE>(edge_end, *this),
|
Chris@16
|
1289 m_distribution.block_size(process_id(m_process_group), numverts),
|
Chris@16
|
1290 get(vertex_local, *this),
|
Chris@16
|
1291 local_vertex<csr_vertex_owner_map<process_id_type, vertex_descriptor>,
|
Chris@16
|
1292 process_id_type> (get(vertex_owner, *this), process_id(pg)),
|
Chris@16
|
1293 prop)
|
Chris@16
|
1294 {
|
Chris@16
|
1295 }
|
Chris@16
|
1296
|
Chris@16
|
1297 // -----------------------------------------------------------------
|
Chris@16
|
1298 // Vertex Global Property Map
|
Chris@16
|
1299 template<typename ProcessID, typename Key>
|
Chris@16
|
1300 class csr_vertex_global_map
|
Chris@16
|
1301 {
|
Chris@16
|
1302 public:
|
Chris@16
|
1303 // -----------------------------------------------------------------
|
Chris@16
|
1304 // Readable Property Map concept requirements
|
Chris@16
|
1305 typedef std::pair<ProcessID, Key> value_type;
|
Chris@16
|
1306 typedef value_type reference;
|
Chris@16
|
1307 typedef Key key_type;
|
Chris@16
|
1308 typedef readable_property_map_tag category;
|
Chris@16
|
1309 };
|
Chris@16
|
1310
|
Chris@16
|
1311 template<typename ProcessID, typename Key>
|
Chris@16
|
1312 inline std::pair<ProcessID, Key>
|
Chris@16
|
1313 get(csr_vertex_global_map<ProcessID, Key>,
|
Chris@16
|
1314 typename csr_vertex_global_map<ProcessID, Key>::key_type k)
|
Chris@16
|
1315 {
|
Chris@16
|
1316 const int local_index_bits = sizeof(Key) * CHAR_BIT - processor_bits;
|
Chris@16
|
1317 const Key local_index_mask = Key(-1) >> processor_bits;
|
Chris@16
|
1318
|
Chris@16
|
1319 return std::pair<ProcessID, Key>(k >> local_index_bits,
|
Chris@16
|
1320 k & local_index_mask);
|
Chris@16
|
1321 }
|
Chris@16
|
1322
|
Chris@16
|
1323 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1324 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_global_t>
|
Chris@16
|
1325 {
|
Chris@16
|
1326 public:
|
Chris@16
|
1327 typedef csr_vertex_global_map<
|
Chris@16
|
1328 typename ProcessGroup::process_id_type,
|
Chris@16
|
1329 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor> type;
|
Chris@16
|
1330 typedef type const_type;
|
Chris@16
|
1331 };
|
Chris@16
|
1332
|
Chris@16
|
1333 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1334 inline
|
Chris@16
|
1335 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_global_t>::type
|
Chris@16
|
1336 get(vertex_global_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1337 {
|
Chris@16
|
1338 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_global_t>
|
Chris@16
|
1339 ::type result_type;
|
Chris@16
|
1340 return result_type();
|
Chris@16
|
1341 }
|
Chris@16
|
1342
|
Chris@16
|
1343 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1344 inline
|
Chris@16
|
1345 std::pair<typename ProcessGroup::process_id_type,
|
Chris@16
|
1346 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor>
|
Chris@16
|
1347 get(vertex_global_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1348 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1349 {
|
Chris@16
|
1350 return get(vertex_global,
|
Chris@16
|
1351 const_cast<const BOOST_DISTRIB_CSR_GRAPH_TYPE&>(g),
|
Chris@16
|
1352 k);
|
Chris@16
|
1353 }
|
Chris@16
|
1354
|
Chris@16
|
1355 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1356 inline
|
Chris@16
|
1357 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_global_t>::const_type
|
Chris@16
|
1358 get(vertex_global_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1359 {
|
Chris@16
|
1360 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_global_t>
|
Chris@16
|
1361 ::const_type result_type;
|
Chris@16
|
1362 return result_type();
|
Chris@16
|
1363 }
|
Chris@16
|
1364
|
Chris@16
|
1365 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1366 inline
|
Chris@16
|
1367 std::pair<typename ProcessGroup::process_id_type,
|
Chris@16
|
1368 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor>
|
Chris@16
|
1369 get(vertex_global_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1370 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1371 {
|
Chris@16
|
1372 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1373 vertex_descriptor;
|
Chris@16
|
1374 typedef std::pair<typename ProcessGroup::process_id_type, vertex_descriptor>
|
Chris@16
|
1375 result_type;
|
Chris@16
|
1376 const int local_index_bits =
|
Chris@16
|
1377 sizeof(vertex_descriptor) * CHAR_BIT - processor_bits;
|
Chris@16
|
1378 const vertex_descriptor local_index_mask =
|
Chris@16
|
1379 vertex_descriptor(-1) >> processor_bits;
|
Chris@16
|
1380
|
Chris@16
|
1381 return result_type(k >> local_index_bits, k & local_index_mask);
|
Chris@16
|
1382 }
|
Chris@16
|
1383
|
Chris@16
|
1384 // -----------------------------------------------------------------
|
Chris@16
|
1385 // Extra, common functions
|
Chris@16
|
1386 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1387 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1388 vertex(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertices_size_type i,
|
Chris@16
|
1389 const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1390 {
|
Chris@16
|
1391 return g.make_vertex_descriptor(g.distribution()(i),
|
Chris@16
|
1392 g.distribution().local(i));
|
Chris@16
|
1393 }
|
Chris@16
|
1394
|
Chris@16
|
1395 // Unlike for an adjacency_matrix, edge_range and edge take lg(out_degree(i))
|
Chris@16
|
1396 // time
|
Chris@16
|
1397 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1398 inline std::pair<typename BOOST_DISTRIB_CSR_GRAPH_TYPE::out_edge_iterator,
|
Chris@16
|
1399 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::out_edge_iterator>
|
Chris@16
|
1400 edge_range(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor i,
|
Chris@16
|
1401 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor j,
|
Chris@16
|
1402 const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1403 {
|
Chris@16
|
1404 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor Vertex;
|
Chris@16
|
1405 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type EdgeIndex;
|
Chris@16
|
1406 typedef typename std::vector<Vertex>::const_iterator adj_iter;
|
Chris@16
|
1407 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::out_edge_iterator out_edge_iter;
|
Chris@16
|
1408 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor edge_desc;
|
Chris@16
|
1409 std::pair<adj_iter, adj_iter> raw_adjacencies = adjacent_vertices(i, g);
|
Chris@16
|
1410 std::pair<adj_iter, adj_iter> adjacencies =
|
Chris@16
|
1411 std::equal_range(raw_adjacencies.first, raw_adjacencies.second, j);
|
Chris@16
|
1412 EdgeIndex idx_begin = adjacencies.first - g.base().m_forward.m_column.begin();
|
Chris@16
|
1413 EdgeIndex idx_end = adjacencies.second - g.base().m_forward.m_column.begin();
|
Chris@16
|
1414 return std::make_pair(out_edge_iter(edge_desc(i, idx_begin)),
|
Chris@16
|
1415 out_edge_iter(edge_desc(i, idx_end)));
|
Chris@16
|
1416 }
|
Chris@16
|
1417
|
Chris@16
|
1418 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1419 inline std::pair<typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor, bool>
|
Chris@16
|
1420 edge(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor i,
|
Chris@16
|
1421 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor j,
|
Chris@16
|
1422 const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1423 {
|
Chris@16
|
1424 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::out_edge_iterator out_edge_iter;
|
Chris@16
|
1425 std::pair<out_edge_iter, out_edge_iter> range = edge_range(i, j, g);
|
Chris@16
|
1426 if (range.first == range.second)
|
Chris@16
|
1427 return std::make_pair(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor(),
|
Chris@16
|
1428 false);
|
Chris@16
|
1429 else
|
Chris@16
|
1430 return std::make_pair(*range.first, true);
|
Chris@16
|
1431 }
|
Chris@16
|
1432
|
Chris@16
|
1433 // A helper that turns requests for property maps for const graphs
|
Chris@16
|
1434 // into property maps for non-const graphs.
|
Chris@16
|
1435 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename Property>
|
Chris@16
|
1436 class property_map<const BOOST_DISTRIB_CSR_GRAPH_TYPE, Property>
|
Chris@16
|
1437 {
|
Chris@16
|
1438 public:
|
Chris@16
|
1439 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, Property>
|
Chris@16
|
1440 ::const_type type;
|
Chris@16
|
1441 typedef type const_type;
|
Chris@16
|
1442 };
|
Chris@16
|
1443
|
Chris@16
|
1444 // -----------------------------------------------------------------
|
Chris@16
|
1445 // Structural modifiers
|
Chris@16
|
1446
|
Chris@16
|
1447 #if 0
|
Chris@16
|
1448 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1449 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1450 add_vertex(BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1451 { return g.add_vertex(); }
|
Chris@16
|
1452
|
Chris@16
|
1453 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1454 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1455 add_vertex(const typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_bundled& p,
|
Chris@16
|
1456 BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1457 { return g.add_vertex(p); }
|
Chris@16
|
1458
|
Chris@16
|
1459 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1460 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1461 add_vertices(typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertices_size_type count,
|
Chris@16
|
1462 BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1463 { return g.add_vertices(count); }
|
Chris@16
|
1464
|
Chris@16
|
1465 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator>
|
Chris@16
|
1466 void
|
Chris@16
|
1467 add_edges(InputIterator first, InputIterator last,
|
Chris@16
|
1468 BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1469 { g.add_edges(first, last); }
|
Chris@16
|
1470
|
Chris@16
|
1471 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator,
|
Chris@16
|
1472 typename EdgePropertyIterator>
|
Chris@16
|
1473 void
|
Chris@16
|
1474 add_edges(InputIterator first, InputIterator last,
|
Chris@16
|
1475 EdgePropertyIterator ep_iter,
|
Chris@16
|
1476 EdgePropertyIterator ep_iter_end,
|
Chris@16
|
1477 BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1478 { return g.add_edges(first, last, ep_iter, ep_iter_end); }
|
Chris@16
|
1479
|
Chris@16
|
1480 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator>
|
Chris@16
|
1481 void
|
Chris@16
|
1482 add_edges_sorted(InputIterator first, InputIterator last,
|
Chris@16
|
1483 BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1484 { return g.add_edges_sorted(first, last); }
|
Chris@16
|
1485
|
Chris@16
|
1486 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename InputIterator,
|
Chris@16
|
1487 typename EdgePropertyIterator>
|
Chris@16
|
1488 void
|
Chris@16
|
1489 add_edges_sorted(InputIterator first_sorted, InputIterator last_sorted,
|
Chris@16
|
1490 EdgePropertyIterator ep_iter_sorted,
|
Chris@16
|
1491 BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1492 { g.add_edges_sorted(first_sorted, last_sorted, ep_iter_sorted); }
|
Chris@16
|
1493 #endif
|
Chris@16
|
1494
|
Chris@16
|
1495 // -----------------------------------------------------------------
|
Chris@16
|
1496 // Vertex Owner Property Map
|
Chris@16
|
1497 template<typename ProcessID, typename Key>
|
Chris@16
|
1498 class csr_vertex_owner_map
|
Chris@16
|
1499 {
|
Chris@16
|
1500 public:
|
Chris@16
|
1501 // -----------------------------------------------------------------
|
Chris@16
|
1502 // Readable Property Map concept requirements
|
Chris@16
|
1503 typedef ProcessID value_type;
|
Chris@16
|
1504 typedef value_type reference;
|
Chris@16
|
1505 typedef Key key_type;
|
Chris@16
|
1506 typedef readable_property_map_tag category;
|
Chris@16
|
1507 };
|
Chris@16
|
1508
|
Chris@16
|
1509 template<typename ProcessID, typename Key>
|
Chris@16
|
1510 inline ProcessID
|
Chris@16
|
1511 get(csr_vertex_owner_map<ProcessID, Key> pm,
|
Chris@16
|
1512 typename csr_vertex_owner_map<ProcessID, Key>::key_type k)
|
Chris@16
|
1513 {
|
Chris@16
|
1514 const int local_index_bits = sizeof(Key) * CHAR_BIT - processor_bits;
|
Chris@16
|
1515 return k >> local_index_bits;
|
Chris@16
|
1516 }
|
Chris@16
|
1517
|
Chris@16
|
1518 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1519 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_owner_t>
|
Chris@16
|
1520 {
|
Chris@16
|
1521 public:
|
Chris@16
|
1522 typedef csr_vertex_owner_map<
|
Chris@16
|
1523 typename ProcessGroup::process_id_type,
|
Chris@16
|
1524 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor> type;
|
Chris@16
|
1525 typedef type const_type;
|
Chris@16
|
1526 };
|
Chris@16
|
1527
|
Chris@16
|
1528 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1529 inline
|
Chris@16
|
1530 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_owner_t>::type
|
Chris@16
|
1531 get(vertex_owner_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1532 {
|
Chris@16
|
1533 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_owner_t>
|
Chris@16
|
1534 ::type result_type;
|
Chris@16
|
1535 return result_type();
|
Chris@16
|
1536 }
|
Chris@16
|
1537
|
Chris@16
|
1538 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1539 inline typename ProcessGroup::process_id_type
|
Chris@16
|
1540 get(vertex_owner_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1541 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1542 {
|
Chris@16
|
1543 return get(vertex_owner,
|
Chris@16
|
1544 const_cast<const BOOST_DISTRIB_CSR_GRAPH_TYPE&>(g),
|
Chris@16
|
1545 k);
|
Chris@16
|
1546 }
|
Chris@16
|
1547
|
Chris@16
|
1548 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1549 inline
|
Chris@16
|
1550 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_owner_t>::const_type
|
Chris@16
|
1551 get(vertex_owner_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1552 {
|
Chris@16
|
1553 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_owner_t>
|
Chris@16
|
1554 ::const_type result_type;
|
Chris@16
|
1555 return result_type();
|
Chris@16
|
1556 }
|
Chris@16
|
1557
|
Chris@16
|
1558 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1559 inline typename ProcessGroup::process_id_type
|
Chris@16
|
1560 get(vertex_owner_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1561 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1562 {
|
Chris@16
|
1563 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1564 vertex_descriptor;
|
Chris@16
|
1565 const int local_index_bits =
|
Chris@16
|
1566 sizeof(vertex_descriptor) * CHAR_BIT - processor_bits;
|
Chris@16
|
1567 return k >> local_index_bits;
|
Chris@16
|
1568 }
|
Chris@16
|
1569
|
Chris@16
|
1570 // -----------------------------------------------------------------
|
Chris@16
|
1571 // Vertex Local Property Map
|
Chris@16
|
1572 template<typename Key>
|
Chris@16
|
1573 class csr_vertex_local_map
|
Chris@16
|
1574 {
|
Chris@16
|
1575 public:
|
Chris@16
|
1576 // -----------------------------------------------------------------
|
Chris@16
|
1577 // Readable Property Map concept requirements
|
Chris@16
|
1578 typedef Key value_type;
|
Chris@16
|
1579 typedef value_type reference;
|
Chris@16
|
1580 typedef Key key_type;
|
Chris@16
|
1581 typedef readable_property_map_tag category;
|
Chris@16
|
1582 };
|
Chris@16
|
1583
|
Chris@16
|
1584 template<typename Key>
|
Chris@16
|
1585 inline Key
|
Chris@16
|
1586 get(csr_vertex_local_map<Key> pm,
|
Chris@16
|
1587 typename csr_vertex_local_map<Key>::key_type k)
|
Chris@16
|
1588 {
|
Chris@16
|
1589 const Key local_index_mask = Key(-1) >> processor_bits;
|
Chris@16
|
1590 return k & local_index_mask;
|
Chris@16
|
1591 }
|
Chris@16
|
1592
|
Chris@16
|
1593 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1594 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_t>
|
Chris@16
|
1595 {
|
Chris@16
|
1596 public:
|
Chris@16
|
1597 typedef csr_vertex_local_map<
|
Chris@16
|
1598 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor> type;
|
Chris@16
|
1599 typedef type const_type;
|
Chris@16
|
1600 };
|
Chris@16
|
1601
|
Chris@16
|
1602 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1603 inline
|
Chris@16
|
1604 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_t>::type
|
Chris@16
|
1605 get(vertex_local_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1606 {
|
Chris@16
|
1607 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_t>
|
Chris@16
|
1608 ::type result_type;
|
Chris@16
|
1609 return result_type();
|
Chris@16
|
1610 }
|
Chris@16
|
1611
|
Chris@16
|
1612 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1613 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1614 get(vertex_local_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1615 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1616 {
|
Chris@16
|
1617 return get(vertex_local,
|
Chris@16
|
1618 const_cast<const BOOST_DISTRIB_CSR_GRAPH_TYPE&>(g),
|
Chris@16
|
1619 k);
|
Chris@16
|
1620 }
|
Chris@16
|
1621
|
Chris@16
|
1622 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1623 inline
|
Chris@16
|
1624 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_t>::const_type
|
Chris@16
|
1625 get(vertex_local_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1626 {
|
Chris@16
|
1627 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_t>
|
Chris@16
|
1628 ::const_type result_type;
|
Chris@16
|
1629 return result_type();
|
Chris@16
|
1630 }
|
Chris@16
|
1631
|
Chris@16
|
1632 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1633 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1634 get(vertex_local_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1635 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1636 {
|
Chris@16
|
1637 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1638 vertex_descriptor;
|
Chris@16
|
1639 const vertex_descriptor local_index_mask =
|
Chris@16
|
1640 vertex_descriptor(-1) >> processor_bits;
|
Chris@16
|
1641 return k & local_index_mask;
|
Chris@16
|
1642 }
|
Chris@16
|
1643
|
Chris@16
|
1644 // -----------------------------------------------------------------
|
Chris@16
|
1645 // Vertex Index Property Map
|
Chris@16
|
1646 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1647 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_index_t>
|
Chris@16
|
1648 {
|
Chris@16
|
1649 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE,
|
Chris@16
|
1650 vertex_global_t>::const_type
|
Chris@16
|
1651 global_map;
|
Chris@16
|
1652 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::process_group_type
|
Chris@16
|
1653 process_group_type;
|
Chris@16
|
1654
|
Chris@16
|
1655 typedef property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_t> local;
|
Chris@16
|
1656
|
Chris@16
|
1657 public:
|
Chris@16
|
1658 typedef local_property_map<process_group_type,
|
Chris@16
|
1659 global_map,
|
Chris@16
|
1660 typename local::type> type;
|
Chris@16
|
1661 typedef local_property_map<process_group_type,
|
Chris@16
|
1662 global_map,
|
Chris@16
|
1663 typename local::const_type> const_type;
|
Chris@16
|
1664 };
|
Chris@16
|
1665
|
Chris@16
|
1666 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1667 inline
|
Chris@16
|
1668 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_index_t>::type
|
Chris@16
|
1669 get(vertex_index_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1670 {
|
Chris@16
|
1671 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_index_t>
|
Chris@16
|
1672 ::type result_type;
|
Chris@16
|
1673
|
Chris@16
|
1674 return result_type(g.process_group(), get(vertex_global, g),
|
Chris@16
|
1675 get(vertex_local, g));
|
Chris@16
|
1676 }
|
Chris@16
|
1677
|
Chris@16
|
1678 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1679 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertices_size_type
|
Chris@16
|
1680 get(vertex_index_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1681 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1682 {
|
Chris@16
|
1683 return get(vertex_local, g, k);
|
Chris@16
|
1684 }
|
Chris@16
|
1685
|
Chris@16
|
1686 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1687 inline
|
Chris@16
|
1688 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_index_t>::const_type
|
Chris@16
|
1689 get(vertex_index_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1690 {
|
Chris@16
|
1691 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_index_t>
|
Chris@16
|
1692 ::const_type result_type;
|
Chris@16
|
1693 return result_type(g.process_group(), get(vertex_global, g),
|
Chris@16
|
1694 get(vertex_local, g));
|
Chris@16
|
1695 }
|
Chris@16
|
1696
|
Chris@16
|
1697 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1698 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertices_size_type
|
Chris@16
|
1699 get(vertex_index_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1700 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1701 {
|
Chris@16
|
1702 return get(vertex_local, g, k);
|
Chris@16
|
1703 }
|
Chris@16
|
1704
|
Chris@16
|
1705 // -----------------------------------------------------------------
|
Chris@16
|
1706 // Vertex Local Index Property Map
|
Chris@16
|
1707 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1708 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_index_t>
|
Chris@16
|
1709 : public property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_t> { };
|
Chris@16
|
1710
|
Chris@16
|
1711 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1712 inline
|
Chris@16
|
1713 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_index_t>::type
|
Chris@16
|
1714 get(vertex_local_index_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1715 {
|
Chris@16
|
1716 return get(vertex_local, g);
|
Chris@16
|
1717 }
|
Chris@16
|
1718
|
Chris@16
|
1719 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1720 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertices_size_type
|
Chris@16
|
1721 get(vertex_local_index_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1722 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1723 {
|
Chris@16
|
1724 return get(vertex_local, g, k);
|
Chris@16
|
1725 }
|
Chris@16
|
1726
|
Chris@16
|
1727 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1728 inline
|
Chris@16
|
1729 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, vertex_local_index_t>::const_type
|
Chris@16
|
1730 get(vertex_local_index_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1731 {
|
Chris@16
|
1732 return get(vertex_local, g);
|
Chris@16
|
1733 }
|
Chris@16
|
1734
|
Chris@16
|
1735 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1736 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertices_size_type
|
Chris@16
|
1737 get(vertex_local_index_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1738 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor k)
|
Chris@16
|
1739 {
|
Chris@16
|
1740 return get(vertex_local, g, k);
|
Chris@16
|
1741 }
|
Chris@16
|
1742
|
Chris@16
|
1743 // -----------------------------------------------------------------
|
Chris@16
|
1744 // Edge Global Property Map
|
Chris@16
|
1745 template<typename ProcessID, typename Vertex, typename EdgeIndex>
|
Chris@16
|
1746 class csr_edge_global_map
|
Chris@16
|
1747 {
|
Chris@16
|
1748 public:
|
Chris@16
|
1749 // -----------------------------------------------------------------
|
Chris@16
|
1750 // Readable Property Map concept requirements
|
Chris@16
|
1751 typedef detail::csr_edge_descriptor<Vertex, EdgeIndex> key_type;
|
Chris@16
|
1752 typedef std::pair<ProcessID, detail::csr_edge_descriptor<Vertex, EdgeIndex> > value_type;
|
Chris@16
|
1753 typedef value_type reference;
|
Chris@16
|
1754 typedef readable_property_map_tag category;
|
Chris@16
|
1755 };
|
Chris@16
|
1756
|
Chris@16
|
1757 template<typename ProcessID, typename Vertex, typename EdgeIndex>
|
Chris@16
|
1758 inline std::pair<ProcessID, detail::csr_edge_descriptor<Vertex, EdgeIndex> >
|
Chris@16
|
1759 get(csr_edge_global_map<ProcessID, Vertex, EdgeIndex> pm,
|
Chris@16
|
1760 typename csr_edge_global_map<ProcessID, Vertex, EdgeIndex>::key_type k)
|
Chris@16
|
1761 {
|
Chris@16
|
1762 const int local_index_bits = sizeof(Vertex) * CHAR_BIT - processor_bits;
|
Chris@16
|
1763 const Vertex local_index_mask = Vertex(-1) >> processor_bits;
|
Chris@16
|
1764 return std::pair<ProcessID, detail::csr_edge_descriptor<Vertex, EdgeIndex> >
|
Chris@16
|
1765 ((k.src >> local_index_bits),
|
Chris@16
|
1766 detail::csr_edge_descriptor<Vertex, EdgeIndex>(k.src & local_index_mask, k.idx));
|
Chris@16
|
1767 }
|
Chris@16
|
1768
|
Chris@16
|
1769 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1770 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_global_t>
|
Chris@16
|
1771 {
|
Chris@16
|
1772 public:
|
Chris@16
|
1773 typedef csr_edge_global_map<
|
Chris@16
|
1774 typename ProcessGroup::process_id_type,
|
Chris@16
|
1775 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor,
|
Chris@16
|
1776 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type> type;
|
Chris@16
|
1777 typedef type const_type;
|
Chris@16
|
1778 };
|
Chris@16
|
1779
|
Chris@16
|
1780 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1781 inline
|
Chris@16
|
1782 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_global_t>::type
|
Chris@16
|
1783 get(edge_global_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1784 {
|
Chris@16
|
1785 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_global_t>
|
Chris@16
|
1786 ::type result_type;
|
Chris@16
|
1787 return result_type();
|
Chris@16
|
1788 }
|
Chris@16
|
1789
|
Chris@16
|
1790 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1791 inline
|
Chris@16
|
1792 std::pair<typename ProcessGroup::process_id_type,
|
Chris@16
|
1793 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::base_type::edge_descriptor>
|
Chris@16
|
1794 get(edge_global_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1795 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor k)
|
Chris@16
|
1796 {
|
Chris@16
|
1797 return get(edge_global,
|
Chris@16
|
1798 const_cast<const BOOST_DISTRIB_CSR_GRAPH_TYPE&>(g),
|
Chris@16
|
1799 k);
|
Chris@16
|
1800 }
|
Chris@16
|
1801
|
Chris@16
|
1802 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1803 inline
|
Chris@16
|
1804 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_global_t>::const_type
|
Chris@16
|
1805 get(edge_global_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1806 {
|
Chris@16
|
1807 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_global_t>
|
Chris@16
|
1808 ::const_type result_type;
|
Chris@16
|
1809 return result_type();
|
Chris@16
|
1810 }
|
Chris@16
|
1811
|
Chris@16
|
1812 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1813 inline
|
Chris@16
|
1814 std::pair<typename ProcessGroup::process_id_type,
|
Chris@16
|
1815 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::base_type::edge_descriptor>
|
Chris@16
|
1816 get(edge_global_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1817 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor k)
|
Chris@16
|
1818 {
|
Chris@16
|
1819 typedef typename BOOST_DISTRIB_CSR_GRAPH_TYPE::vertex_descriptor
|
Chris@16
|
1820 vertex_descriptor;
|
Chris@16
|
1821
|
Chris@16
|
1822 const int local_index_bits =
|
Chris@16
|
1823 sizeof(vertex_descriptor) * CHAR_BIT - processor_bits;
|
Chris@16
|
1824 const typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type local_index_mask =
|
Chris@16
|
1825 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type(-1) >> processor_bits;
|
Chris@16
|
1826
|
Chris@16
|
1827 typedef std::pair<typename ProcessGroup::process_id_type,
|
Chris@16
|
1828 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::base_type::edge_descriptor>
|
Chris@16
|
1829 result_type;
|
Chris@16
|
1830
|
Chris@16
|
1831 return result_type(k.src >> local_index_bits,
|
Chris@16
|
1832 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::base_type::edge_descriptor
|
Chris@16
|
1833 (k.src & local_index_mask, k.idx));
|
Chris@16
|
1834 }
|
Chris@16
|
1835
|
Chris@16
|
1836 // -----------------------------------------------------------------
|
Chris@16
|
1837 // Edge Index Property Map
|
Chris@16
|
1838 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1839 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_index_t>
|
Chris@16
|
1840 {
|
Chris@16
|
1841 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_global_t>
|
Chris@16
|
1842 ::type global_map;
|
Chris@16
|
1843
|
Chris@16
|
1844 public:
|
Chris@16
|
1845 typedef local_property_map<
|
Chris@16
|
1846 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::process_group_type,
|
Chris@16
|
1847 global_map,
|
Chris@16
|
1848 typename property_map<typename BOOST_DISTRIB_CSR_GRAPH_TYPE::base_type, edge_index_t>::type
|
Chris@16
|
1849 > type;
|
Chris@16
|
1850 typedef type const_type;
|
Chris@16
|
1851 };
|
Chris@16
|
1852
|
Chris@16
|
1853 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1854 inline
|
Chris@16
|
1855 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_index_t>::type
|
Chris@16
|
1856 get(edge_index_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1857 {
|
Chris@16
|
1858 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_index_t>
|
Chris@16
|
1859 ::type result_type;
|
Chris@16
|
1860 return result_type(g.process_group(), get(edge_global, g),
|
Chris@16
|
1861 get(edge_index, g.base()));
|
Chris@16
|
1862 }
|
Chris@16
|
1863
|
Chris@16
|
1864 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1865 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type
|
Chris@16
|
1866 get(edge_index_t, BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1867 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor k)
|
Chris@16
|
1868 {
|
Chris@16
|
1869 return k.idx;
|
Chris@16
|
1870 }
|
Chris@16
|
1871
|
Chris@16
|
1872 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1873 inline
|
Chris@16
|
1874 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_index_t>::const_type
|
Chris@16
|
1875 get(edge_index_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1876 {
|
Chris@16
|
1877 typedef typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, edge_index_t>
|
Chris@16
|
1878 ::const_type result_type;
|
Chris@16
|
1879 return result_type(g.process_group(), get(edge_global, g),
|
Chris@16
|
1880 get(edge_index, g.base()));
|
Chris@16
|
1881 }
|
Chris@16
|
1882
|
Chris@16
|
1883 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS>
|
Chris@16
|
1884 inline typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edges_size_type
|
Chris@16
|
1885 get(edge_index_t, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g,
|
Chris@16
|
1886 typename BOOST_DISTRIB_CSR_GRAPH_TYPE::edge_descriptor k)
|
Chris@16
|
1887 {
|
Chris@16
|
1888 return k.idx;
|
Chris@16
|
1889 }
|
Chris@16
|
1890
|
Chris@16
|
1891 template <BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
|
Chris@16
|
1892 class property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, Tag> {
|
Chris@16
|
1893 typedef BOOST_DISTRIB_CSR_GRAPH_TYPE graph_type;
|
Chris@16
|
1894 typedef typename graph_type::process_group_type process_group_type;
|
Chris@16
|
1895 typedef typename graph_type::base_type base_graph_type;
|
Chris@16
|
1896 typedef typename property_map<base_graph_type, Tag>::type
|
Chris@16
|
1897 local_pmap;
|
Chris@16
|
1898 typedef typename property_map<base_graph_type, Tag>::const_type
|
Chris@16
|
1899 local_const_pmap;
|
Chris@16
|
1900
|
Chris@16
|
1901 typedef graph_traits<graph_type> traits;
|
Chris@16
|
1902 typedef typename graph_traits<base_graph_type>::vertex_descriptor local_vertex;
|
Chris@16
|
1903 typedef typename property_traits<local_pmap>::key_type local_key_type;
|
Chris@16
|
1904
|
Chris@16
|
1905 typedef typename property_traits<local_pmap>::value_type value_type;
|
Chris@16
|
1906
|
Chris@16
|
1907 typedef typename property_map<graph_type, vertex_global_t>::const_type
|
Chris@16
|
1908 vertex_global_map;
|
Chris@16
|
1909 typedef typename property_map<graph_type, edge_global_t>::const_type
|
Chris@16
|
1910 edge_global_map;
|
Chris@16
|
1911
|
Chris@16
|
1912 typedef typename mpl::if_<is_same<typename detail::property_kind_from_graph<base_graph_type, Tag>::type,
|
Chris@16
|
1913 vertex_property_tag>,
|
Chris@16
|
1914 vertex_global_map, edge_global_map>::type
|
Chris@16
|
1915 global_map;
|
Chris@16
|
1916
|
Chris@16
|
1917 public:
|
Chris@16
|
1918 typedef ::boost::parallel::distributed_property_map<
|
Chris@16
|
1919 process_group_type, global_map, local_pmap> type;
|
Chris@16
|
1920
|
Chris@16
|
1921 typedef ::boost::parallel::distributed_property_map<
|
Chris@16
|
1922 process_group_type, global_map, local_const_pmap> const_type;
|
Chris@16
|
1923 };
|
Chris@16
|
1924
|
Chris@16
|
1925 template <BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
|
Chris@16
|
1926 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, Tag>::type
|
Chris@16
|
1927 get(Tag tag, BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1928 {
|
Chris@16
|
1929 typedef BOOST_DISTRIB_CSR_GRAPH_TYPE Graph;
|
Chris@16
|
1930 typedef typename property_map<Graph, Tag>::type result_type;
|
Chris@16
|
1931 typedef typename property_traits<result_type>::value_type value_type;
|
Chris@16
|
1932 typedef typename property_reduce<Tag>::template apply<value_type>
|
Chris@16
|
1933 reduce;
|
Chris@16
|
1934
|
Chris@16
|
1935 typedef typename mpl::if_<is_same<typename detail::property_kind_from_graph<Graph, Tag>::type,
|
Chris@16
|
1936 vertex_property_tag>,
|
Chris@16
|
1937 vertex_global_t, edge_global_t>::type
|
Chris@16
|
1938 global_map_t;
|
Chris@16
|
1939
|
Chris@16
|
1940 return result_type(g.process_group(), get(global_map_t(), g),
|
Chris@16
|
1941 get(tag, g.base()), reduce());
|
Chris@16
|
1942 }
|
Chris@16
|
1943
|
Chris@16
|
1944 template<BOOST_DISTRIB_CSR_GRAPH_TEMPLATE_PARMS, typename Tag>
|
Chris@16
|
1945 typename property_map<BOOST_DISTRIB_CSR_GRAPH_TYPE, Tag>::const_type
|
Chris@16
|
1946 get(Tag tag, const BOOST_DISTRIB_CSR_GRAPH_TYPE& g)
|
Chris@16
|
1947 {
|
Chris@16
|
1948 typedef BOOST_DISTRIB_CSR_GRAPH_TYPE Graph;
|
Chris@16
|
1949 typedef typename property_map<Graph, Tag>::const_type result_type;
|
Chris@16
|
1950 typedef typename property_traits<result_type>::value_type value_type;
|
Chris@16
|
1951 typedef typename property_reduce<Tag>::template apply<value_type>
|
Chris@16
|
1952 reduce;
|
Chris@16
|
1953
|
Chris@16
|
1954 typedef typename property_traits<result_type>::key_type descriptor;
|
Chris@16
|
1955 typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
|
Chris@16
|
1956 typedef typename mpl::if_<is_same<descriptor, vertex_descriptor>,
|
Chris@16
|
1957 vertex_global_t, edge_global_t>::type
|
Chris@16
|
1958 global_map_t;
|
Chris@16
|
1959
|
Chris@16
|
1960 return result_type(g.process_group(), get(global_map_t(), g),
|
Chris@16
|
1961 get(tag, g.base()), reduce());
|
Chris@16
|
1962 }
|
Chris@16
|
1963
|
Chris@16
|
1964 namespace mpi {
|
Chris@16
|
1965 template<typename Vertex, typename EdgeIndex>
|
Chris@16
|
1966 struct is_mpi_datatype<boost::detail::csr_edge_descriptor<Vertex, EdgeIndex> >
|
Chris@16
|
1967 : mpl::true_ { };
|
Chris@16
|
1968 }
|
Chris@16
|
1969
|
Chris@16
|
1970 namespace serialization {
|
Chris@16
|
1971 template<typename Vertex, typename EdgeIndex>
|
Chris@16
|
1972 struct is_bitwise_serializable<boost::detail::csr_edge_descriptor<Vertex, EdgeIndex> >
|
Chris@16
|
1973 : mpl::true_ { };
|
Chris@16
|
1974
|
Chris@16
|
1975 template<typename Vertex, typename EdgeIndex>
|
Chris@16
|
1976 struct implementation_level<boost::detail::csr_edge_descriptor<Vertex, EdgeIndex> >
|
Chris@16
|
1977 : mpl::int_<object_serializable> {} ;
|
Chris@16
|
1978
|
Chris@16
|
1979 template<typename Vertex, typename EdgeIndex>
|
Chris@16
|
1980 struct tracking_level<boost::detail::csr_edge_descriptor<Vertex, EdgeIndex> >
|
Chris@16
|
1981 : mpl::int_<track_never> {} ;
|
Chris@16
|
1982
|
Chris@16
|
1983 }
|
Chris@16
|
1984
|
Chris@16
|
1985 } // end namespace boost
|
Chris@16
|
1986
|
Chris@16
|
1987 #endif // BOOST_GRAPH_DISTRIBUTED_CSR_HPP
|