// Copyright (C) 2004-2006 The Trustees of Indiana University. // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // Authors: Douglas Gregor // Andrew Lumsdaine #ifndef BOOST_GRAPH_LOCAL_SUBGRAPH_HPP #define BOOST_GRAPH_LOCAL_SUBGRAPH_HPP #ifndef BOOST_GRAPH_USE_MPI #error "Parallel BGL files should not be included unless has been included" #endif #include #include #include #include #include namespace boost { namespace graph { namespace detail { // Optionally, virtually derive from a base class template struct derive_from_if; template struct derive_from_if : virtual Base {}; template struct derive_from_if {}; template struct derive_from_if_tag_is : derive_from_if<(is_base_and_derived::value || is_same::value), NewBase> { }; } } // end namespace graph::detail template class is_local_edge { public: typedef bool result_type; typedef typename graph_traits::edge_descriptor argument_type; is_local_edge() : g(0) {} is_local_edge(DistributedGraph& g) : g(&g), owner(get(vertex_owner, g)) {} // Since either the source or target vertex must be local, the // equivalence of their owners indicates a local edge. result_type operator()(const argument_type& e) const { return get(owner, source(e, *g)) == get(owner, target(e, *g)); } private: DistributedGraph* g; typename property_map::const_type owner; }; template class is_local_vertex { public: typedef bool result_type; typedef typename graph_traits::vertex_descriptor argument_type; is_local_vertex() : g(0) {} is_local_vertex(DistributedGraph& g) : g(&g), owner(get(vertex_owner, g)) { } // Since either the source or target vertex must be local, the // equivalence of their owners indicates a local edge. result_type operator()(const argument_type& v) const { return get(owner, v) == process_id(process_group(*g)); } private: DistributedGraph* g; typename property_map::const_type owner; }; template class local_subgraph : public filtered_graph, is_local_vertex > { typedef filtered_graph, is_local_vertex > inherited; typedef typename graph_traits::traversal_category inherited_category; public: struct traversal_category : graph::detail::derive_from_if_tag_is, graph::detail::derive_from_if_tag_is, graph::detail::derive_from_if_tag_is, graph::detail::derive_from_if_tag_is, graph::detail::derive_from_if_tag_is, graph::detail::derive_from_if_tag_is { }; local_subgraph(DistributedGraph& g) : inherited(g, is_local_edge(g), is_local_vertex(g)), g(g) { } // Distributed Container typedef typename boost::graph::parallel::process_group_type::type process_group_type; process_group_type& process_group() { using boost::graph::parallel::process_group; return process_group(g); } const process_group_type& process_group() const { using boost::graph::parallel::process_group; return boost::graph::parallel::process_group(g); } DistributedGraph& base() { return g; } const DistributedGraph& base() const { return g; } private: DistributedGraph& g; }; template class property_map, PropertyTag> : public property_map { }; template class property_map, PropertyTag> { public: typedef typename property_map::const_type type; typedef type const_type; }; template inline typename property_map, PropertyTag>::type get(PropertyTag p, local_subgraph& g) { return get(p, g.base()); } template inline typename property_map, PropertyTag> ::const_type get(PropertyTag p, const local_subgraph& g) { return get(p, g.base()); } template inline local_subgraph make_local_subgraph(DistributedGraph& g) { return local_subgraph(g); } } // end namespace boost #endif // BOOST_GRAPH_LOCAL_SUBGRAPH_HPP