// Copyright (C) 2007-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) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #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 namespace std; using boost::graph::distributed::mpi_process_group; struct EdgeProperties { EdgeProperties() { cash = 0; } EdgeProperties(double c) : cash(c) { } public: double cash; friend class serialization::access; template void serialize(Archive & ar, const unsigned int version) { ar & cash; } }; typedef boost::adjacency_list, bidirectionalS, property, EdgeProperties> Graph; typedef graph_traits::vertex_descriptor Vertex; typedef graph_traits::edge_descriptor Edge; struct remote_key_e { remote_key_e(int p = -1, Edge l = Edge()) : processor(p){local_key = &l; } int processor; Edge* local_key; template void serialize(Archiver& ar, const unsigned int /*version*/) { ar & processor & local_key; } }; namespace boost { template<> struct hash { std::size_t operator()(const remote_key_e& key) const { std::size_t hash = hash_value(key.processor); hash_combine(hash, key.local_key); return hash; } }; } inline bool operator==(const remote_key_e& x, const remote_key_e& y) { return x.processor == y.processor && (*(x.local_key)) == (*(y.local_key)); } struct remote_key_to_global_e { typedef readable_property_map_tag category; typedef remote_key_e key_type; typedef std::pair value_type; typedef value_type reference; }; inline std::pair get(remote_key_to_global_e, const remote_key_e& key) { return std::make_pair(key.processor, *(key.local_key)); } template struct rank_accumulate_reducer { static const bool non_default_resolver = false; // The default rank of an unknown node template T operator()(const K&) const {return T(0); } template T operator()(const K&, const T& x, const T& y) const { return x; } }; int test_main(int argc, char** argv) { boost::mpi::environment env(argc, argv); //Random scale-free typedef boost::unique_rmat_iterator RMATGen; boost::minstd_rand gen; Graph g(RMATGen(gen, 20, 100, 0.57, 0.19, 0.19, 0.05), RMATGen(), 20); mpi_process_group pg = g.process_group(); int rank = graph::distributed::process_id(g.process_group()); std::ofstream myfile; char numstr[21]; // enough to hold all numbers up to 64-bits sprintf(numstr, "file.%d.graphml", rank); myfile.open (numstr); property_map::type index_map = get(vertex_index, g); property_map::type ecash = get(&EdgeProperties::cash, g); typedef property_map::type ecash_map; //Vertex iterator distributed property maps typedef property_map::const_type VertexIndexMap; typedef iterator_property_map::iterator, VertexIndexMap> d_index_map; std::vector index_S(num_vertices(g), std::numeric_limits::max()); d_index_map d_index(index_S.begin(), get(vertex_index, g)); d_index.set_reduce(rank_accumulate_reducer()); graph_traits::out_edge_iterator ei, edge_end, einext; graph_traits::in_edge_iterator ei_i, edge_end_i; //Vertex initializations BGL_FORALL_VERTICES(v, g, Graph) { put(d_index, v, 10* rank + index_map[v]); } //Edge iterator distributed property maps typedef boost::parallel::distributed_property_map Dist_ecash_Map; Dist_ecash_Map d_ecash = boost::parallel::make_distributed_property_map(pg, remote_key_to_global_e(), ecash); d_ecash.set_reduce(rank_accumulate_reducer()); synchronize(g); for (int t = 0; t < 2; t++) { myfile< "<