annotate DEPENDENCIES/generic/include/boost/graph/distributed/distributed_graph_utility.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (C) 2005-2006 The Trustees of Indiana University.
Chris@16 2 // Use, modification and distribution is subject to the Boost Software
Chris@16 3 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 4 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5
Chris@16 6 // Authors: Peter Gottschling
Chris@16 7 // Douglas Gregor
Chris@16 8 // Andrew Lumsdaine
Chris@16 9
Chris@16 10 #include <boost/graph/iteration_macros.hpp>
Chris@16 11 #include <boost/property_map/parallel/global_index_map.hpp>
Chris@16 12
Chris@16 13 #ifndef BOOST_GRAPH_DISTRIBUTED_GRAPH_UTILITY_INCLUDE
Chris@16 14 #define BOOST_GRAPH_DISTRIBUTED_GRAPH_UTILITY_INCLUDE
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 namespace boost { namespace graph {
Chris@16 21
Chris@16 22 template <class Property, class Graph>
Chris@16 23 void property_on_inedges(Property p, const Graph& g)
Chris@16 24 {
Chris@16 25 BGL_FORALL_VERTICES_T(u, g, Graph)
Chris@16 26 BGL_FORALL_INEDGES_T(u, e, g, Graph)
Chris@16 27 request(p, e);
Chris@16 28 synchronize(p);
Chris@16 29 }
Chris@16 30
Chris@16 31 // For reverse graphs
Chris@16 32 template <class Property, class Graph>
Chris@16 33 void property_on_outedges(Property p, const Graph& g)
Chris@16 34 {
Chris@16 35 BGL_FORALL_VERTICES_T(u, g, Graph)
Chris@16 36 BGL_FORALL_OUTEDGES_T(u, e, g, Graph)
Chris@16 37 request(p, e);
Chris@16 38 synchronize(p);
Chris@16 39 }
Chris@16 40
Chris@16 41 template <class Property, class Graph>
Chris@16 42 void property_on_successors(Property p, const Graph& g)
Chris@16 43 {
Chris@16 44 BGL_FORALL_VERTICES_T(u, g, Graph)
Chris@16 45 BGL_FORALL_OUTEDGES_T(u, e, g, Graph)
Chris@16 46 request(p, target(e, g));
Chris@16 47 synchronize(p);
Chris@16 48 }
Chris@16 49
Chris@16 50 template <class Property, class Graph>
Chris@16 51 void property_on_predecessors(Property p, const Graph& g)
Chris@16 52 {
Chris@16 53 BGL_FORALL_VERTICES_T(u, g, Graph)
Chris@16 54 BGL_FORALL_INEDGES_T(u, e, g, Graph)
Chris@16 55 request(p, source(e, g));
Chris@16 56 synchronize(p);
Chris@16 57 }
Chris@16 58
Chris@16 59 // Like successors and predecessors but saves one synchronize (and a call)
Chris@16 60 template <class Property, class Graph>
Chris@16 61 void property_on_adjacents(Property p, const Graph& g)
Chris@16 62 {
Chris@16 63 BGL_FORALL_VERTICES_T(u, g, Graph) {
Chris@16 64 BGL_FORALL_OUTEDGES_T(u, e, g, Graph)
Chris@16 65 request(p, target(e, g));
Chris@16 66 BGL_FORALL_INEDGES_T(u, e, g, Graph)
Chris@16 67 request(p, source(e, g));
Chris@16 68 }
Chris@16 69 synchronize(p);
Chris@16 70 }
Chris@16 71
Chris@16 72 template <class PropertyIn, class PropertyOut, class Graph>
Chris@16 73 void copy_vertex_property(PropertyIn p_in, PropertyOut p_out, Graph& g)
Chris@16 74 {
Chris@16 75 BGL_FORALL_VERTICES_T(u, g, Graph)
Chris@16 76 put(p_out, u, get(p_in, g));
Chris@16 77 }
Chris@16 78
Chris@16 79 template <class PropertyIn, class PropertyOut, class Graph>
Chris@16 80 void copy_edge_property(PropertyIn p_in, PropertyOut p_out, Graph& g)
Chris@16 81 {
Chris@16 82 BGL_FORALL_EDGES_T(e, g, Graph)
Chris@16 83 put(p_out, e, get(p_in, g));
Chris@16 84 }
Chris@16 85
Chris@16 86
Chris@16 87 namespace distributed {
Chris@16 88
Chris@16 89 // Define global_index<Graph> global(graph);
Chris@16 90 // Then global(v) returns global index of v
Chris@16 91 template <typename Graph>
Chris@16 92 struct global_index
Chris@16 93 {
Chris@16 94 typedef typename property_map<Graph, vertex_index_t>::const_type
Chris@16 95 VertexIndexMap;
Chris@16 96 typedef typename property_map<Graph, vertex_global_t>::const_type
Chris@16 97 VertexGlobalMap;
Chris@16 98
Chris@16 99 explicit global_index(Graph const& g)
Chris@16 100 : global_index_map(process_group(g), num_vertices(g), get(vertex_index, g),
Chris@16 101 get(vertex_global, g)) {}
Chris@16 102
Chris@16 103 int operator() (typename graph_traits<Graph>::vertex_descriptor v)
Chris@16 104 { return get(global_index_map, v); }
Chris@16 105
Chris@16 106 protected:
Chris@16 107 boost::parallel::global_index_map<VertexIndexMap, VertexGlobalMap>
Chris@16 108 global_index_map;
Chris@16 109 };
Chris@16 110
Chris@16 111 template<typename T>
Chris@16 112 struct additive_reducer {
Chris@16 113 BOOST_STATIC_CONSTANT(bool, non_default_resolver = true);
Chris@16 114
Chris@16 115 template<typename K>
Chris@16 116 T operator()(const K&) const { return T(0); }
Chris@16 117
Chris@16 118 template<typename K>
Chris@16 119 T operator()(const K&, const T& local, const T& remote) const { return local + remote; }
Chris@16 120 };
Chris@16 121
Chris@16 122 template <typename T>
Chris@16 123 struct choose_min_reducer {
Chris@16 124 BOOST_STATIC_CONSTANT(bool, non_default_resolver = true);
Chris@16 125
Chris@16 126 template<typename K>
Chris@16 127 T operator()(const K&) const { return (std::numeric_limits<T>::max)(); }
Chris@16 128
Chris@16 129 template<typename K>
Chris@16 130 T operator()(const K&, const T& x, const T& y) const
Chris@16 131 { return x < y ? x : y; }
Chris@16 132 };
Chris@16 133
Chris@16 134 // To use a property map syntactically like a function
Chris@16 135 template <typename PropertyMap>
Chris@16 136 struct property_map_reader
Chris@16 137 {
Chris@16 138 explicit property_map_reader(PropertyMap pm) : pm(pm) {}
Chris@16 139
Chris@16 140 template <typename T>
Chris@16 141 typename PropertyMap::value_type
Chris@16 142 operator() (const T& v)
Chris@16 143 {
Chris@16 144 return get(pm, v);
Chris@16 145 }
Chris@16 146 private:
Chris@16 147 PropertyMap pm;
Chris@16 148 };
Chris@16 149
Chris@16 150 } // namespace distributed
Chris@16 151
Chris@16 152 }} // namespace boost::graph
Chris@16 153
Chris@16 154 #endif // BOOST_GRAPH_DISTRIBUTED_GRAPH_UTILITY_INCLUDE