1 // Copyright (C) 2004-2006 The Trustees of Indiana University.
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Authors: Douglas Gregor
10 // The placement of this #include probably looks very odd relative to
11 // the #ifndef/#define pair below. However, this placement is
12 // extremely important to allow the various property map headers to be
13 // included in any order.
14 #include <boost/property_map/property_map.hpp>
16 #ifndef BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
17 #define BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
19 #ifndef BOOST_GRAPH_USE_MPI
20 #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
26 /** Property map that accesses an underlying, local property map
27 * using a subset of the global keys.
29 template<typename ProcessGroup
, typename GlobalMap
, typename StorageMap
>
30 class local_property_map
32 typedef typename property_traits
<GlobalMap
>::value_type owner_local_pair
;
35 typedef ProcessGroup process_group_type
;
36 typedef typename property_traits
<StorageMap
>::value_type value_type
;
37 typedef typename property_traits
<GlobalMap
>::key_type key_type
;
38 typedef typename property_traits
<StorageMap
>::reference reference
;
39 typedef typename property_traits
<StorageMap
>::category category
;
41 local_property_map() { }
43 local_property_map(const ProcessGroup
& process_group
,
44 const GlobalMap
& global
, const StorageMap
& storage
)
45 : process_group_(process_group
), global_(global
), storage(storage
) { }
47 reference
operator[](const key_type
& key
)
49 owner_local_pair p
= get(global_
, key
);
50 assert(p
.first
== process_id(process_group_
));
51 return storage
[p
.second
];
54 GlobalMap
& global() const { return global_
; }
55 StorageMap
& base() const { return storage
; }
57 ProcessGroup
& process_group() { return process_group_
; }
58 const ProcessGroup
& process_group() const { return process_group_
; }
61 ProcessGroup process_group_
;
62 mutable GlobalMap global_
;
63 mutable StorageMap storage
;
66 template<typename ProcessGroup
, typename GlobalMap
, typename StorageMap
>
68 typename local_property_map
<ProcessGroup
, GlobalMap
, StorageMap
>::reference
69 get(const local_property_map
<ProcessGroup
, GlobalMap
, StorageMap
>& pm
,
70 typename local_property_map
<ProcessGroup
, GlobalMap
, StorageMap
>::key_type
74 typename property_traits
<GlobalMap
>::value_type p
= get(pm
.global(), key
);
75 return get(pm
.base(), p
.second
);
78 template<typename ProcessGroup
, typename GlobalMap
, typename StorageMap
>
80 put(const local_property_map
<ProcessGroup
, GlobalMap
, StorageMap
>& pm
,
81 typename local_property_map
<ProcessGroup
, GlobalMap
, StorageMap
>
82 ::key_type
const & key
,
83 typename local_property_map
<ProcessGroup
, GlobalMap
, StorageMap
>
84 ::value_type
const& v
)
86 typename property_traits
<GlobalMap
>::value_type p
= get(pm
.global(), key
);
87 assert(p
.first
== process_id(pm
.process_group()));
88 put(pm
.base(), p
.second
, v
);
90 } // end namespace boost
91 #endif // BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP