1 // Copyright (C) 2005-2006 The Trustees of Indiana University.
2 // Use, modification and distribution is subject to the Boost Software
3 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // Authors: Peter Gottschling
10 #include <boost/graph/iteration_macros.hpp>
11 #include <boost/property_map/parallel/global_index_map.hpp>
13 #ifndef BOOST_GRAPH_DISTRIBUTED_GRAPH_UTILITY_INCLUDE
14 #define BOOST_GRAPH_DISTRIBUTED_GRAPH_UTILITY_INCLUDE
16 #ifndef BOOST_GRAPH_USE_MPI
17 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
20 namespace boost { namespace graph {
22 template <class Property, class Graph>
23 void property_on_inedges(Property p, const Graph& g)
25 BGL_FORALL_VERTICES_T(u, g, Graph)
26 BGL_FORALL_INEDGES_T(u, e, g, Graph)
32 template <class Property, class Graph>
33 void property_on_outedges(Property p, const Graph& g)
35 BGL_FORALL_VERTICES_T(u, g, Graph)
36 BGL_FORALL_OUTEDGES_T(u, e, g, Graph)
41 template <class Property, class Graph>
42 void property_on_successors(Property p, const Graph& g)
44 BGL_FORALL_VERTICES_T(u, g, Graph)
45 BGL_FORALL_OUTEDGES_T(u, e, g, Graph)
46 request(p, target(e, g));
50 template <class Property, class Graph>
51 void property_on_predecessors(Property p, const Graph& g)
53 BGL_FORALL_VERTICES_T(u, g, Graph)
54 BGL_FORALL_INEDGES_T(u, e, g, Graph)
55 request(p, source(e, g));
59 // Like successors and predecessors but saves one synchronize (and a call)
60 template <class Property, class Graph>
61 void property_on_adjacents(Property p, const Graph& g)
63 BGL_FORALL_VERTICES_T(u, g, Graph) {
64 BGL_FORALL_OUTEDGES_T(u, e, g, Graph)
65 request(p, target(e, g));
66 BGL_FORALL_INEDGES_T(u, e, g, Graph)
67 request(p, source(e, g));
72 template <class PropertyIn, class PropertyOut, class Graph>
73 void copy_vertex_property(PropertyIn p_in, PropertyOut p_out, Graph& g)
75 BGL_FORALL_VERTICES_T(u, g, Graph)
76 put(p_out, u, get(p_in, g));
79 template <class PropertyIn, class PropertyOut, class Graph>
80 void copy_edge_property(PropertyIn p_in, PropertyOut p_out, Graph& g)
82 BGL_FORALL_EDGES_T(e, g, Graph)
83 put(p_out, e, get(p_in, g));
87 namespace distributed {
89 // Define global_index<Graph> global(graph);
90 // Then global(v) returns global index of v
91 template <typename Graph>
94 typedef typename property_map<Graph, vertex_index_t>::const_type
96 typedef typename property_map<Graph, vertex_global_t>::const_type
99 explicit global_index(Graph const& g)
100 : global_index_map(process_group(g), num_vertices(g), get(vertex_index, g),
101 get(vertex_global, g)) {}
103 int operator() (typename graph_traits<Graph>::vertex_descriptor v)
104 { return get(global_index_map, v); }
107 boost::parallel::global_index_map<VertexIndexMap, VertexGlobalMap>
112 struct additive_reducer {
113 BOOST_STATIC_CONSTANT(bool, non_default_resolver = true);
116 T operator()(const K&) const { return T(0); }
119 T operator()(const K&, const T& local, const T& remote) const { return local + remote; }
122 template <typename T>
123 struct choose_min_reducer {
124 BOOST_STATIC_CONSTANT(bool, non_default_resolver = true);
127 T operator()(const K&) const { return (std::numeric_limits<T>::max)(); }
130 T operator()(const K&, const T& x, const T& y) const
131 { return x < y ? x : y; }
134 // To use a property map syntactically like a function
135 template <typename PropertyMap>
136 struct property_map_reader
138 explicit property_map_reader(PropertyMap pm) : pm(pm) {}
140 template <typename T>
141 typename PropertyMap::value_type
142 operator() (const T& v)
150 } // namespace distributed
152 }} // namespace boost::graph
154 #endif // BOOST_GRAPH_DISTRIBUTED_GRAPH_UTILITY_INCLUDE