// Copyright (C) 2004-2008 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 // Example usage of breadth_first_search algorithm // Enable PBGL interfaces to BGL algorithms #include // Communicate via MPI #include // Breadth-first search algorithm #include // Distributed adjacency list #include // METIS Input #include // Graphviz Output #include // Standard Library includes #include #include #include #include #include #ifdef BOOST_NO_EXCEPTIONS void boost::throw_exception(std::exception const& ex) { std::cout << ex.what() << std::endl; abort(); } #endif using namespace boost; using boost::graph::distributed::mpi_process_group; template struct bfs_discovery_visitor : bfs_visitor<> { bfs_discovery_visitor(DistanceMap distance) : distance(distance) { set_property_map_role(vertex_distance, distance); } template void tree_edge(Edge e, const Graph& g) { typename property_map::type vidxx = get(vertex_index, g); typename graph_traits::vertex_descriptor src = source(e,g); typename graph_traits::vertex_descriptor des = target(e,g); std::size_t new_distance = get(distance, source(e, g)) + 1; std::cout<<"NowVisiting: ("< ("<, directedS >::vertex_descriptor vertex_descriptor; /* An undirected graph with distance values stored on the vertices. */ typedef adjacency_list, directedS, /*Vertex properties=*/property // property > Graph; int main(int argc, char* argv[]) { boost::mpi::environment env(argc,argv); // Parse command-line options int n = 8; Graph g(n); if(process_id(g.process_group()) == 0){ std::vector > allEdges; allEdges.push_back(std::pair(0,1)); allEdges.push_back(std::pair(1,2)); allEdges.push_back(std::pair(2,3)); allEdges.push_back(std::pair(0,4)); allEdges.push_back(std::pair(4,3)); std::vector >::iterator git = allEdges.begin(); for( ; git != allEdges.end(); git++) { add_edge(vertex(git->first, g), vertex(git->second, g), g); } // print_graph(g); } synchronize(g.process_group()); typedef boost::graph::parallel::process_group_type::type process_group_type; typedef property_map::type VertexDistanceMap; typedef graph_traits::vertex_descriptor key_type; typedef property_map::type VertexIndexMap; property_map::type distance = get(vertex_distance, g); property_map::type vertex_global_map = get(vertex_global, g); // property_map::type predecessor = // get(vertex_predecessor, g); typedef graph_traits::vertex_descriptor Vertex; typedef Graph::local_vertex_descriptor local_vertex; std::map pred_map_gd; boost::associative_property_map< std::map< local_vertex, Vertex> > pred_pmap_gd(pred_map_gd); // Get vertex 0 in the graph graph_traits::vertex_descriptor start = vertex(0, g); // Compute BFS levels from vertex 0 property_map::type vidx = get(vertex_index, g); put(distance, start, 0); distance.set_consistency_model(boost::parallel::cm_forward); boost::breadth_first_search (g, start, boost::visitor ( boost::make_bfs_visitor ( std::make_pair ( boost::record_distances(distance, boost::on_tree_edge()), boost::record_predecessors(boost::parallel::make_distributed_property_map(g.process_group(), vertex_global_map, pred_pmap_gd ), boost::on_tree_edge()) ) ) ) ); synchronize(g.process_group()); synchronize(g.process_group()); synchronize(g.process_group()); synchronize(g.process_group()); //synchronize(distance); typedef property_map::const_type VertexIndexMap; typedef property_map::const_type VertexGlobalMap; if(process_id(g.process_group()) == 0){ using boost::graph::parallel::process_group; process_group_type pg = process_group(g); std::cout<<"Finished Parallel BFS "<::vertex_descriptor vtx = vertex(i, g); std::cout<