annotate DEPENDENCIES/generic/include/boost/property_map/parallel/global_index_map.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Copyright 2005 The Trustees of Indiana University.
Chris@16 2
Chris@16 3 // Use, modification and distribution is subject to the Boost Software
Chris@16 4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 5 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 6
Chris@16 7 // Authors: Douglas Gregor
Chris@16 8 // Andrew Lumsdaine
Chris@16 9 #ifndef BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP
Chris@16 10 #define BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP
Chris@16 11
Chris@16 12 #include <boost/property_map/property_map.hpp>
Chris@16 13 #include <vector>
Chris@16 14 #include <boost/shared_ptr.hpp>
Chris@16 15
Chris@16 16 namespace boost { namespace parallel {
Chris@16 17
Chris@16 18 template<typename IndexMap, typename GlobalMap>
Chris@16 19 class global_index_map
Chris@16 20 {
Chris@16 21 public:
Chris@16 22 typedef typename property_traits<IndexMap>::key_type key_type;
Chris@16 23 typedef typename property_traits<IndexMap>::value_type value_type;
Chris@16 24 typedef value_type reference;
Chris@16 25 typedef readable_property_map_tag category;
Chris@16 26
Chris@16 27 template<typename ProcessGroup>
Chris@16 28 global_index_map(ProcessGroup pg, value_type num_local_indices,
Chris@16 29 IndexMap index_map, GlobalMap global)
Chris@16 30 : index_map(index_map), global(global)
Chris@16 31 {
Chris@16 32 typedef typename ProcessGroup::process_id_type process_id_type;
Chris@16 33 starting_index.reset(new std::vector<value_type>(num_processes(pg) + 1));
Chris@16 34 send(pg, 0, 0, num_local_indices);
Chris@16 35 synchronize(pg);
Chris@16 36
Chris@16 37 // Populate starting_index in all processes
Chris@16 38 if (process_id(pg) == 0) {
Chris@16 39 (*starting_index)[0] = 0;
Chris@16 40 for (process_id_type src = 0; src < num_processes(pg); ++src) {
Chris@16 41 value_type n;
Chris@16 42 receive(pg, src, 0, n);
Chris@16 43 (*starting_index)[src + 1] = (*starting_index)[src] + n;
Chris@16 44 }
Chris@16 45 for (process_id_type dest = 1; dest < num_processes(pg); ++dest)
Chris@16 46 send(pg, dest, 1, &starting_index->front(), num_processes(pg));
Chris@16 47 synchronize(pg);
Chris@16 48 } else {
Chris@16 49 synchronize(pg);
Chris@16 50 receive(pg, 0, 1, &starting_index->front(), num_processes(pg));
Chris@16 51 }
Chris@16 52 }
Chris@16 53
Chris@16 54 friend inline value_type
Chris@16 55 get(const global_index_map& gim, const key_type& x)
Chris@16 56 {
Chris@16 57 using boost::get;
Chris@16 58 return (*gim.starting_index)[get(gim.global, x).first]
Chris@16 59 + get(gim.index_map, x);
Chris@16 60 }
Chris@16 61
Chris@16 62 private:
Chris@16 63 shared_ptr<std::vector<value_type> > starting_index;
Chris@16 64 IndexMap index_map;
Chris@16 65 GlobalMap global;
Chris@16 66 };
Chris@16 67
Chris@16 68 } } // end namespace boost::parallel
Chris@16 69
Chris@16 70 #endif // BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP