Chris@16: // Copyright 2005 The Trustees of Indiana University. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software Chris@16: // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // Authors: Douglas Gregor Chris@16: // Andrew Lumsdaine Chris@16: #ifndef BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP Chris@16: #define BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace parallel { Chris@16: Chris@16: template Chris@16: class global_index_map Chris@16: { Chris@16: public: Chris@16: typedef typename property_traits::key_type key_type; Chris@16: typedef typename property_traits::value_type value_type; Chris@16: typedef value_type reference; Chris@16: typedef readable_property_map_tag category; Chris@16: Chris@16: template Chris@16: global_index_map(ProcessGroup pg, value_type num_local_indices, Chris@16: IndexMap index_map, GlobalMap global) Chris@16: : index_map(index_map), global(global) Chris@16: { Chris@16: typedef typename ProcessGroup::process_id_type process_id_type; Chris@16: starting_index.reset(new std::vector(num_processes(pg) + 1)); Chris@16: send(pg, 0, 0, num_local_indices); Chris@16: synchronize(pg); Chris@16: Chris@16: // Populate starting_index in all processes Chris@16: if (process_id(pg) == 0) { Chris@16: (*starting_index)[0] = 0; Chris@16: for (process_id_type src = 0; src < num_processes(pg); ++src) { Chris@16: value_type n; Chris@16: receive(pg, src, 0, n); Chris@16: (*starting_index)[src + 1] = (*starting_index)[src] + n; Chris@16: } Chris@16: for (process_id_type dest = 1; dest < num_processes(pg); ++dest) Chris@16: send(pg, dest, 1, &starting_index->front(), num_processes(pg)); Chris@16: synchronize(pg); Chris@16: } else { Chris@16: synchronize(pg); Chris@16: receive(pg, 0, 1, &starting_index->front(), num_processes(pg)); Chris@16: } Chris@16: } Chris@16: Chris@16: friend inline value_type Chris@16: get(const global_index_map& gim, const key_type& x) Chris@16: { Chris@16: using boost::get; Chris@16: return (*gim.starting_index)[get(gim.global, x).first] Chris@16: + get(gim.index_map, x); Chris@16: } Chris@16: Chris@16: private: Chris@16: shared_ptr > starting_index; Chris@16: IndexMap index_map; Chris@16: GlobalMap global; Chris@16: }; Chris@16: Chris@16: } } // end namespace boost::parallel Chris@16: Chris@16: #endif // BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP