Chris@16
|
1 // Copyright 2004 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_CACHING_PROPERTY_MAP_HPP
|
Chris@16
|
10 #define BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/property_map/property_map.hpp>
|
Chris@16
|
13
|
Chris@16
|
14 namespace boost {
|
Chris@16
|
15
|
Chris@16
|
16 // This probably doesn't belong here
|
Chris@16
|
17 template<typename Key, typename Value>
|
Chris@16
|
18 inline void local_put(dummy_property_map, const Key&, const Value&) {}
|
Chris@16
|
19
|
Chris@16
|
20 namespace parallel {
|
Chris@16
|
21
|
Chris@16
|
22 /** Property map that caches values placed in it but does not
|
Chris@16
|
23 * broadcast values to remote processors. This class template is
|
Chris@16
|
24 * meant as an adaptor for @ref distributed_property_map that
|
Chris@16
|
25 * suppresses communication in the event of a remote @c put operation
|
Chris@16
|
26 * by mapping it to a local @c put operation.
|
Chris@16
|
27 *
|
Chris@16
|
28 * @todo Find a better name for @ref caching_property_map
|
Chris@16
|
29 */
|
Chris@16
|
30 template<typename PropertyMap>
|
Chris@16
|
31 class caching_property_map
|
Chris@16
|
32 {
|
Chris@16
|
33 public:
|
Chris@16
|
34 typedef typename property_traits<PropertyMap>::key_type key_type;
|
Chris@16
|
35 typedef typename property_traits<PropertyMap>::value_type value_type;
|
Chris@16
|
36 typedef typename property_traits<PropertyMap>::reference reference;
|
Chris@16
|
37 typedef typename property_traits<PropertyMap>::category category;
|
Chris@16
|
38
|
Chris@16
|
39 explicit caching_property_map(const PropertyMap& property_map)
|
Chris@16
|
40 : property_map(property_map) {}
|
Chris@16
|
41
|
Chris@16
|
42 PropertyMap& base() { return property_map; }
|
Chris@16
|
43 const PropertyMap& base() const { return property_map; }
|
Chris@16
|
44
|
Chris@16
|
45 template<typename Reduce>
|
Chris@16
|
46 void set_reduce(const Reduce& reduce)
|
Chris@16
|
47 { property_map.set_reduce(reduce); }
|
Chris@16
|
48
|
Chris@16
|
49 void reset() { property_map.reset(); }
|
Chris@16
|
50
|
Chris@16
|
51 #if 0
|
Chris@16
|
52 reference operator[](const key_type& key) const
|
Chris@16
|
53 {
|
Chris@16
|
54 return property_map[key];
|
Chris@16
|
55 }
|
Chris@16
|
56 #endif
|
Chris@16
|
57
|
Chris@16
|
58 private:
|
Chris@16
|
59 PropertyMap property_map;
|
Chris@16
|
60 };
|
Chris@16
|
61
|
Chris@16
|
62 template<typename PropertyMap, typename Key>
|
Chris@16
|
63 inline typename caching_property_map<PropertyMap>::value_type
|
Chris@16
|
64 get(const caching_property_map<PropertyMap>& pm, const Key& key)
|
Chris@16
|
65 { return get(pm.base(), key); }
|
Chris@16
|
66
|
Chris@16
|
67 template<typename PropertyMap, typename Key, typename Value>
|
Chris@16
|
68 inline void
|
Chris@16
|
69 local_put(const caching_property_map<PropertyMap>& pm, const Key& key,
|
Chris@16
|
70 const Value& value)
|
Chris@16
|
71 { local_put(pm.base(), key, value); }
|
Chris@16
|
72
|
Chris@16
|
73 template<typename PropertyMap, typename Key, typename Value>
|
Chris@16
|
74 inline void
|
Chris@16
|
75 cache(const caching_property_map<PropertyMap>& pm, const Key& key,
|
Chris@16
|
76 const Value& value)
|
Chris@16
|
77 { cache(pm.base(), key, value); }
|
Chris@16
|
78
|
Chris@16
|
79 template<typename PropertyMap, typename Key, typename Value>
|
Chris@16
|
80 inline void
|
Chris@16
|
81 put(const caching_property_map<PropertyMap>& pm, const Key& key,
|
Chris@16
|
82 const Value& value)
|
Chris@16
|
83 { local_put(pm.base(), key, value); }
|
Chris@16
|
84
|
Chris@16
|
85 template<typename PropertyMap>
|
Chris@16
|
86 inline caching_property_map<PropertyMap>
|
Chris@16
|
87 make_caching_property_map(const PropertyMap& pm)
|
Chris@16
|
88 { return caching_property_map<PropertyMap>(pm); }
|
Chris@16
|
89
|
Chris@16
|
90 } } // end namespace boost::parallel
|
Chris@16
|
91
|
Chris@16
|
92 #endif // BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
|