File indexing completed on 2025-01-18 09:50:15
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP
0010 #define BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP
0011
0012 #include <boost/property_map/property_map.hpp>
0013 #include <vector>
0014 #include <boost/shared_ptr.hpp>
0015
0016 namespace boost { namespace parallel {
0017
0018 template<typename IndexMap, typename GlobalMap>
0019 class global_index_map
0020 {
0021 public:
0022 typedef typename property_traits<IndexMap>::key_type key_type;
0023 typedef typename property_traits<IndexMap>::value_type value_type;
0024 typedef value_type reference;
0025 typedef readable_property_map_tag category;
0026
0027 template<typename ProcessGroup>
0028 global_index_map(ProcessGroup pg, value_type num_local_indices,
0029 IndexMap index_map, GlobalMap global)
0030 : index_map(index_map), global(global)
0031 {
0032 typedef typename ProcessGroup::process_id_type process_id_type;
0033 starting_index.reset(new std::vector<value_type>(num_processes(pg) + 1));
0034 send(pg, 0, 0, num_local_indices);
0035 synchronize(pg);
0036
0037
0038 if (process_id(pg) == 0) {
0039 (*starting_index)[0] = 0;
0040 for (process_id_type src = 0; src < num_processes(pg); ++src) {
0041 value_type n;
0042 receive(pg, src, 0, n);
0043 (*starting_index)[src + 1] = (*starting_index)[src] + n;
0044 }
0045 for (process_id_type dest = 1; dest < num_processes(pg); ++dest)
0046 send(pg, dest, 1, &starting_index->front(), num_processes(pg));
0047 synchronize(pg);
0048 } else {
0049 synchronize(pg);
0050 receive(pg, 0, 1, &starting_index->front(), num_processes(pg));
0051 }
0052 }
0053
0054 friend inline value_type
0055 get(const global_index_map& gim, const key_type& x)
0056 {
0057 using boost::get;
0058 return (*gim.starting_index)[get(gim.global, x).first]
0059 + get(gim.index_map, x);
0060 }
0061
0062 private:
0063 shared_ptr<std::vector<value_type> > starting_index;
0064 IndexMap index_map;
0065 GlobalMap global;
0066 };
0067
0068 } }
0069
0070 #endif