caching_property_map.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2004 The Trustees of Indiana University.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Authors: Douglas Gregor
  6. // Andrew Lumsdaine
  7. #ifndef BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
  8. #define BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
  9. #ifndef BOOST_GRAPH_USE_MPI
  10. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  11. #endif
  12. #include <boost/property_map/property_map.hpp>
  13. namespace boost {
  14. // This probably doesn't belong here
  15. template<typename Key, typename Value>
  16. inline void local_put(dummy_property_map, const Key&, const Value&) {}
  17. namespace parallel {
  18. /** Property map that caches values placed in it but does not
  19. * broadcast values to remote processors. This class template is
  20. * meant as an adaptor for @ref distributed_property_map that
  21. * suppresses communication in the event of a remote @c put operation
  22. * by mapping it to a local @c put operation.
  23. *
  24. * @todo Find a better name for @ref caching_property_map
  25. */
  26. template<typename PropertyMap>
  27. class caching_property_map
  28. {
  29. public:
  30. typedef typename property_traits<PropertyMap>::key_type key_type;
  31. typedef typename property_traits<PropertyMap>::value_type value_type;
  32. typedef typename property_traits<PropertyMap>::reference reference;
  33. typedef typename property_traits<PropertyMap>::category category;
  34. explicit caching_property_map(const PropertyMap& property_map)
  35. : property_map(property_map) {}
  36. PropertyMap& base() { return property_map; }
  37. const PropertyMap& base() const { return property_map; }
  38. template<typename Reduce>
  39. void set_reduce(const Reduce& reduce)
  40. { property_map.set_reduce(reduce); }
  41. void reset() { property_map.reset(); }
  42. #if 0
  43. reference operator[](const key_type& key) const
  44. {
  45. return property_map[key];
  46. }
  47. #endif
  48. private:
  49. PropertyMap property_map;
  50. };
  51. template<typename PropertyMap, typename Key>
  52. inline typename caching_property_map<PropertyMap>::value_type
  53. get(const caching_property_map<PropertyMap>& pm, const Key& key)
  54. { return get(pm.base(), key); }
  55. template<typename PropertyMap, typename Key, typename Value>
  56. inline void
  57. local_put(const caching_property_map<PropertyMap>& pm, const Key& key,
  58. const Value& value)
  59. { local_put(pm.base(), key, value); }
  60. template<typename PropertyMap, typename Key, typename Value>
  61. inline void
  62. cache(const caching_property_map<PropertyMap>& pm, const Key& key,
  63. const Value& value)
  64. { cache(pm.base(), key, value); }
  65. template<typename PropertyMap, typename Key, typename Value>
  66. inline void
  67. put(const caching_property_map<PropertyMap>& pm, const Key& key,
  68. const Value& value)
  69. { local_put(pm.base(), key, value); }
  70. template<typename PropertyMap>
  71. inline caching_property_map<PropertyMap>
  72. make_caching_property_map(const PropertyMap& pm)
  73. { return caching_property_map<PropertyMap>(pm); }
  74. } } // end namespace boost::parallel
  75. #endif // BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP