#include #include #include #include using namespace boost; using boost::graph::distributed::mpi_process_group; //----------------------------------------------------------------------------- struct Topo { friend class boost::serialization::access; template void serialize(Archive & ar, const unsigned int version) { ar & user_id & rank_id ; } Topo( int uid=0, int rid=-1 ) : user_id(uid), rank_id(rid) {} int user_id; int rank_id; friend std::ostream& operator<< (std::ostream& o, const Topo& t) { o << "uid = " << t.user_id << ", rid = " << t.rank_id; return o; } }; //----------------------------------------------------------------------------- // named vertices in a graph namespace boost { namespace graph { template<> struct internal_vertex_name< Topo > { typedef multi_index::member< Topo, int, &Topo::user_id > type; }; template<> struct internal_vertex_constructor< Topo > { typedef vertex_from_name< Topo > type; }; }} typedef adjacency_list< vecS, distributedS< mpi_process_group, vecS >, directedS, Topo > Graph; int main(int argc, char* argv[]) { boost::mpi::environment env(argc,argv); boost::mpi::communicator world; Graph g; add_vertex( 42, g ); add_vertex( 99, g ); add_edge( 42, 99, g); synchronize(g.process_group()); property_map< Graph, vertex_bundle_t>::type vpb_map = get(vertex_bundle, g); if ( world.rank() == 0 ) std::cout << " ********** after init." << std::endl; write_graphviz(std::cout, g, make_label_writer( vpb_map )); // now, let us redistribute property_map< Graph, int Topo::*>::type rid_map = get(&Topo::rank_id, g); put( rid_map, *find_vertex(42,g), 1 ); put( rid_map, *find_vertex(99,g), 0 ); if ( world.rank() == 0 ) std::cout << " ********** after rank." << std::endl; write_graphviz(std::cout, g, make_label_writer( vpb_map )); // Perform the actual redistribution g.redistribute( rid_map ); if ( world.rank() == 0 ) std::cout << " ********** after redi." << std::endl; write_graphviz(std::cout, g, make_label_writer( vpb_map )); return 0; }