distributed_property_map.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // Copyright (C) 2004-2008 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. // Nick Edmonds
  7. // Andrew Lumsdaine
  8. // The placement of this #include probably looks very odd relative to
  9. // the #ifndef/#define pair below. However, this placement is
  10. // extremely important to allow the various property map headers to be
  11. // included in any order.
  12. #include <boost/property_map/property_map.hpp>
  13. #ifndef BOOST_PARALLEL_DISTRIBUTED_PROPERTY_MAP_HPP
  14. #define BOOST_PARALLEL_DISTRIBUTED_PROPERTY_MAP_HPP
  15. #ifndef BOOST_GRAPH_USE_MPI
  16. #error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
  17. #endif
  18. #include <boost/assert.hpp>
  19. #include <boost/type_traits/is_base_and_derived.hpp>
  20. #include <boost/shared_ptr.hpp>
  21. #include <boost/weak_ptr.hpp>
  22. #include <boost/optional.hpp>
  23. #include <boost/graph/parallel/process_group.hpp>
  24. #include <boost/graph/detail/edge.hpp>
  25. #include <boost/function/function1.hpp>
  26. #include <vector>
  27. #include <set>
  28. #include <boost/graph/parallel/basic_reduce.hpp>
  29. #include <boost/graph/parallel/detail/untracked_pair.hpp>
  30. #include <boost/type_traits/is_same.hpp>
  31. #include <boost/property_map/parallel/local_property_map.hpp>
  32. #include <map>
  33. #include <boost/version.hpp>
  34. #include <boost/graph/distributed/unsafe_serialize.hpp>
  35. #include <boost/multi_index_container.hpp>
  36. #include <boost/multi_index/hashed_index.hpp>
  37. #include <boost/multi_index/member.hpp>
  38. #include <boost/multi_index/sequenced_index.hpp>
  39. // Serialization functions for constructs we use
  40. #include <boost/serialization/utility.hpp>
  41. namespace boost { namespace parallel {
  42. using boost::graph::parallel::trigger_receive_context;
  43. namespace detail {
  44. /**************************************************************************
  45. * Metafunction that degrades an Lvalue Property Map category tag to
  46. * a Read Write Property Map category tag.
  47. **************************************************************************/
  48. template<bool IsLvaluePropertyMap>
  49. struct make_nonlvalue_property_map
  50. {
  51. template<typename T> struct apply { typedef T type; };
  52. };
  53. template<>
  54. struct make_nonlvalue_property_map<true>
  55. {
  56. template<typename>
  57. struct apply
  58. {
  59. typedef read_write_property_map_tag type;
  60. };
  61. };
  62. /**************************************************************************
  63. * Performs a "put" on a property map so long as the property map is
  64. * a Writable Property Map or a mutable Lvalue Property Map. This
  65. * is required because the distributed property map's message
  66. * handler handles "put" messages even for a const property map,
  67. * although receipt of a "put" message is ill-formed.
  68. **************************************************************************/
  69. template<bool IsLvaluePropertyMap>
  70. struct maybe_put_in_lvalue_pm
  71. {
  72. template<typename PropertyMap, typename Key, typename Value>
  73. static inline void
  74. do_put(PropertyMap, const Key&, const Value&)
  75. { BOOST_ASSERT(false); }
  76. };
  77. template<>
  78. struct maybe_put_in_lvalue_pm<true>
  79. {
  80. template<typename PropertyMap, typename Key, typename Value>
  81. static inline void
  82. do_put(PropertyMap pm, const Key& key, const Value& value)
  83. {
  84. using boost::put;
  85. put(pm, key, value);
  86. }
  87. };
  88. template<typename PropertyMap, typename Key, typename Value>
  89. inline void
  90. maybe_put_impl(PropertyMap pm, const Key& key, const Value& value,
  91. writable_property_map_tag)
  92. {
  93. using boost::put;
  94. put(pm, key, value);
  95. }
  96. template<typename PropertyMap, typename Key, typename Value>
  97. inline void
  98. maybe_put_impl(PropertyMap pm, const Key& key, const Value& value,
  99. lvalue_property_map_tag)
  100. {
  101. typedef typename property_traits<PropertyMap>::value_type value_type;
  102. typedef typename property_traits<PropertyMap>::reference reference;
  103. // DPG TBD: Some property maps are improperly characterized as
  104. // lvalue_property_maps, when in fact they do not provide true
  105. // references. The most typical example is those property maps
  106. // built from vector<bool> and its iterators, which deal with
  107. // proxies. We don't want to mischaracterize these as not having a
  108. // "put" operation, so we only consider an lvalue_property_map as
  109. // constant if its reference is const value_type&. In fact, this
  110. // isn't even quite correct (think of a
  111. // vector<bool>::const_iterator), but at present C++ doesn't
  112. // provide us with any alternatives.
  113. typedef is_same<const value_type&, reference> is_constant;
  114. maybe_put_in_lvalue_pm<(!is_constant::value)>::do_put(pm, key, value);
  115. }
  116. template<typename PropertyMap, typename Key, typename Value>
  117. inline void
  118. maybe_put_impl(PropertyMap, const Key&, const Value&, ...)
  119. { BOOST_ASSERT(false); }
  120. template<typename PropertyMap, typename Key, typename Value>
  121. inline void
  122. maybe_put(PropertyMap pm, const Key& key, const Value& value)
  123. {
  124. maybe_put_impl(pm, key, value,
  125. typename property_traits<PropertyMap>::category());
  126. }
  127. } // end namespace detail
  128. /** The consistency model used by the distributed property map. */
  129. enum consistency_model {
  130. cm_forward = 1 << 0,
  131. cm_backward = 1 << 1,
  132. cm_bidirectional = cm_forward | cm_backward,
  133. cm_flush = 1 << 2,
  134. cm_reset = 1 << 3,
  135. cm_clear = 1 << 4
  136. };
  137. /** Distributed property map adaptor.
  138. *
  139. * The distributed property map adaptor is a property map whose
  140. * stored values are distributed across multiple non-overlapping
  141. * memory spaces on different processes. Values local to the current
  142. * process are stored within a local property map and may be
  143. * immediately accessed via @c get and @c put. Values stored on
  144. * remote processes may also be access via @c get and @c put, but the
  145. * behavior differs slightly:
  146. *
  147. * - @c put operations update a local ghost cell and send a "put"
  148. * message to the process that owns the value. The owner is free to
  149. * update its own "official" value or may ignore the put request.
  150. *
  151. * - @c get operations returns the contents of the local ghost
  152. * cell. If no ghost cell is available, one is created using the
  153. * default value provided by the "reduce" operation. See, e.g.,
  154. * @ref basic_reduce and @ref property_reduce.
  155. *
  156. * Using distributed property maps requires a bit more care than using
  157. * local, sequential property maps. While the syntax and semantics are
  158. * similar, distributed property maps may contain out-of-date
  159. * information that can only be guaranteed to be synchronized by
  160. * calling the @ref synchronize function in all processes.
  161. *
  162. * To address the issue of out-of-date values, distributed property
  163. * maps are supplied with a reduction operation. The reduction
  164. * operation has two roles:
  165. *
  166. * -# When a value is needed for a remote key but no value is
  167. * immediately available, the reduction operation provides a
  168. * suitable default. For instance, a distributed property map
  169. * storing distances may have a reduction operation that returns
  170. * an infinite value as the default, whereas a distributed
  171. * property map for vertex colors may return white as the
  172. * default.
  173. *
  174. * -# When a value is received from a remote process, the process
  175. * owning the key associated with that value must determine which
  176. * value---the locally stored value, the value received from a
  177. * remote process, or some combination of the two---will be
  178. * stored as the "official" value in the property map. The
  179. * reduction operation transforms the local and remote values
  180. * into the "official" value to be stored.
  181. *
  182. * @tparam ProcessGroup the type of the process group over which the
  183. * property map is distributed and is also the medium for
  184. * communication.
  185. *
  186. * @tparam StorageMap the type of the property map that will
  187. * store values for keys local to this processor. The @c value_type of
  188. * this property map will become the @c value_type of the distributed
  189. * property map. The distributed property map models the same property
  190. * map concepts as the @c LocalPropertyMap, with one exception: a
  191. * distributed property map cannot be an LvaluePropertyMap (because
  192. * remote values are not addressable), and is therefore limited to
  193. * ReadWritePropertyMap.
  194. */
  195. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  196. class distributed_property_map
  197. {
  198. public:
  199. /// The key type of the property map.
  200. typedef typename property_traits<GlobalMap>::key_type key_type;
  201. /// The value type of the property map.
  202. typedef typename property_traits<StorageMap>::value_type value_type;
  203. typedef typename property_traits<StorageMap>::reference reference;
  204. typedef ProcessGroup process_group_type;
  205. private:
  206. typedef distributed_property_map self_type;
  207. typedef typename property_traits<StorageMap>::category local_category;
  208. typedef typename property_traits<StorageMap>::key_type local_key_type;
  209. typedef typename property_traits<GlobalMap>::value_type owner_local_pair;
  210. typedef typename ProcessGroup::process_id_type process_id_type;
  211. enum property_map_messages {
  212. /** A request to store a value in a property map. The message
  213. * contains a std::pair<key, data>.
  214. */
  215. property_map_put,
  216. /** A request to retrieve a particular value in a property
  217. * map. The message contains a key. The owner of that key will
  218. * reply with a value.
  219. */
  220. property_map_get,
  221. /** A request to update values stored on a remote processor. The
  222. * message contains a vector of keys for which the source
  223. * requests updated values. This message will only be transmitted
  224. * during synchronization.
  225. */
  226. property_map_multiget,
  227. /** A request to store values in a ghost cell. This message
  228. * contains a vector of key/value pairs corresponding to the
  229. * sequence of keys sent to the source processor.
  230. */
  231. property_map_multiget_reply,
  232. /** The payload containing a vector of local key-value pairs to be
  233. * put into the remote property map. A key-value std::pair will be
  234. * used to store each local key-value pair.
  235. */
  236. property_map_multiput
  237. };
  238. // Code from Joaquín M López Muñoz to work around unusual implementation of
  239. // std::pair in VC++ 10:
  240. template<typename First,typename Second>
  241. class pair_first_extractor {
  242. typedef std::pair<First,Second> value_type;
  243. public:
  244. typedef First result_type;
  245. const result_type& operator()(const value_type& x) const {
  246. return x.first;
  247. }
  248. result_type& operator()(value_type& x) const {
  249. return x.first;
  250. }
  251. };
  252. public:
  253. /// The type of the ghost cells
  254. typedef multi_index::multi_index_container<
  255. std::pair<key_type, value_type>,
  256. multi_index::indexed_by<
  257. multi_index::sequenced<>,
  258. multi_index::hashed_unique<
  259. pair_first_extractor<key_type, value_type>
  260. >
  261. >
  262. > ghost_cells_type;
  263. /// Iterator into the ghost cells
  264. typedef typename ghost_cells_type::iterator iterator;
  265. /// Key-based index into the ghost cells
  266. typedef typename ghost_cells_type::template nth_index<1>::type
  267. ghost_cells_key_index_type;
  268. /// Iterator into the ghost cells (by key)
  269. typedef typename ghost_cells_key_index_type::iterator key_iterator;
  270. /** The property map category. A distributed property map cannot be
  271. * an Lvalue Property Map, because values on remote processes cannot
  272. * be addresses.
  273. */
  274. typedef typename detail::make_nonlvalue_property_map<
  275. (is_base_and_derived<lvalue_property_map_tag, local_category>::value
  276. || is_same<lvalue_property_map_tag, local_category>::value)>
  277. ::template apply<local_category>::type category;
  278. /** Default-construct a distributed property map. This function
  279. * creates an initialized property map that must be assigned to a
  280. * valid value before being used. It is only provided here because
  281. * property maps must be Default Constructible.
  282. */
  283. distributed_property_map() {}
  284. /** Construct a distributed property map. Builds a distributed
  285. * property map communicating over the given process group and using
  286. * the given local property map for storage. Since no reduction
  287. * operation is provided, the default reduction operation @c
  288. * basic_reduce<value_type> is used.
  289. */
  290. distributed_property_map(const ProcessGroup& pg, const GlobalMap& global,
  291. const StorageMap& pm)
  292. : data(new data_t(pg, global, pm, basic_reduce<value_type>(), false))
  293. {
  294. typedef handle_message<basic_reduce<value_type> > Handler;
  295. data->ghost_cells.reset(new ghost_cells_type());
  296. Handler handler(data);
  297. data->process_group.replace_handler(handler, true);
  298. data->process_group.template get_receiver<Handler>()
  299. ->setup_triggers(data->process_group);
  300. }
  301. /** Construct a distributed property map. Builds a distributed
  302. * property map communicating over the given process group and using
  303. * the given local property map for storage. The given @p reduce
  304. * parameter is used as the reduction operation.
  305. */
  306. template<typename Reduce>
  307. distributed_property_map(const ProcessGroup& pg, const GlobalMap& global,
  308. const StorageMap& pm,
  309. const Reduce& reduce);
  310. ~distributed_property_map();
  311. /// Set the reduce operation of the distributed property map.
  312. template<typename Reduce>
  313. void set_reduce(const Reduce& reduce);
  314. // Set the consistency model for the distributed property map
  315. void set_consistency_model(int model);
  316. // Get the consistency model
  317. int get_consistency_model() const { return data->model; }
  318. // Set the maximum number of ghost cells that we are allowed to
  319. // maintain. If 0, all ghost cells will be retained.
  320. void set_max_ghost_cells(std::size_t max_ghost_cells);
  321. // Clear out all ghost cells
  322. void clear();
  323. // Reset the values in all ghost cells to the default value
  324. void reset();
  325. // Flush all values destined for remote processors
  326. void flush();
  327. reference operator[](const key_type& key) const
  328. {
  329. owner_local_pair p = get(data->global, key);
  330. if (p.first == process_id(data->process_group)) {
  331. return data->storage[p.second];
  332. } else {
  333. return cell(key);
  334. }
  335. }
  336. process_group_type process_group() const
  337. {
  338. return data->process_group.base();
  339. }
  340. StorageMap& base() { return data->storage; }
  341. const StorageMap& base() const { return data->storage; }
  342. /** Sends a "put" request.
  343. * \internal
  344. *
  345. */
  346. void
  347. request_put(process_id_type p, const key_type& k, const value_type& v) const
  348. {
  349. send(data->process_group, p, property_map_put,
  350. boost::parallel::detail::make_untracked_pair(k, v));
  351. }
  352. /** Access the ghost cell for the given key.
  353. * \internal
  354. */
  355. value_type& cell(const key_type& k, bool request_if_missing = true) const;
  356. /** Perform synchronization
  357. * \internal
  358. */
  359. void do_synchronize();
  360. const GlobalMap& global() const { return data->global; }
  361. GlobalMap& global() { return data->global; }
  362. struct data_t
  363. {
  364. data_t(const ProcessGroup& pg, const GlobalMap& global,
  365. const StorageMap& pm, const function1<value_type, key_type>& dv,
  366. bool has_default_resolver)
  367. : process_group(pg), global(global), storage(pm),
  368. ghost_cells(), max_ghost_cells(1000000), get_default_value(dv),
  369. has_default_resolver(has_default_resolver), model(cm_forward) { }
  370. /// The process group
  371. ProcessGroup process_group;
  372. /// A mapping from the keys of this property map to the global
  373. /// descriptor.
  374. GlobalMap global;
  375. /// Local property map
  376. StorageMap storage;
  377. /// The ghost cells
  378. shared_ptr<ghost_cells_type> ghost_cells;
  379. /// The maximum number of ghost cells we are permitted to hold. If
  380. /// zero, we are permitted to have an infinite number of ghost
  381. /// cells.
  382. std::size_t max_ghost_cells;
  383. /// Default value for remote ghost cells, as defined by the
  384. /// reduction operation.
  385. function1<value_type, key_type> get_default_value;
  386. /// True if this resolver is the "default" resolver, meaning that
  387. /// we should not be able to get() a default value; it needs to be
  388. /// request()ed first.
  389. bool has_default_resolver;
  390. // Current consistency model
  391. int model;
  392. // Function that resets all of the ghost cells to their default
  393. // values. It knows the type of the resolver, so we can eliminate
  394. // a large number of calls through function pointers.
  395. void (data_t::*reset)();
  396. // Clear out all ghost cells
  397. void clear();
  398. // Flush all values destined for remote processors
  399. void flush();
  400. // Send out requests to "refresh" the values of ghost cells that
  401. // we're holding.
  402. void refresh_ghost_cells();
  403. private:
  404. template<typename Resolver> void do_reset();
  405. friend class distributed_property_map;
  406. };
  407. friend struct data_t;
  408. shared_ptr<data_t> data;
  409. private:
  410. // Prunes the least recently used ghost cells until we have @c
  411. // max_ghost_cells or fewer ghost cells.
  412. void prune_ghost_cells() const;
  413. /** Handles incoming messages.
  414. *
  415. * This function object is responsible for handling all incoming
  416. * messages for the distributed property map.
  417. */
  418. template<typename Reduce>
  419. struct handle_message
  420. {
  421. explicit handle_message(const shared_ptr<data_t>& data,
  422. const Reduce& reduce = Reduce())
  423. : data_ptr(data), reduce(reduce) { }
  424. void operator()(process_id_type source, int tag);
  425. /// Individual message handlers
  426. void
  427. handle_put(int source, int tag,
  428. const boost::parallel::detail::untracked_pair<key_type, value_type>& data,
  429. trigger_receive_context);
  430. value_type
  431. handle_get(int source, int tag, const key_type& data,
  432. trigger_receive_context);
  433. void
  434. handle_multiget(int source, int tag,
  435. const std::vector<key_type>& data,
  436. trigger_receive_context);
  437. void
  438. handle_multiget_reply
  439. (int source, int tag,
  440. const std::vector<boost::parallel::detail::untracked_pair<key_type, value_type> >& msg,
  441. trigger_receive_context);
  442. void
  443. handle_multiput
  444. (int source, int tag,
  445. const std::vector<unsafe_pair<local_key_type, value_type> >& data,
  446. trigger_receive_context);
  447. void setup_triggers(process_group_type& pg);
  448. private:
  449. weak_ptr<data_t> data_ptr;
  450. Reduce reduce;
  451. };
  452. /* Sets up the next stage in a multi-stage synchronization, for
  453. bidirectional consistency. */
  454. struct on_synchronize
  455. {
  456. explicit on_synchronize(const shared_ptr<data_t>& data) : data_ptr(data) { }
  457. void operator()();
  458. private:
  459. weak_ptr<data_t> data_ptr;
  460. };
  461. };
  462. /* An implementation helper macro for the common case of naming
  463. distributed property maps with all of the normal template
  464. parameters. */
  465. #define PBGL_DISTRIB_PMAP \
  466. distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
  467. /* Request that the value for the given remote key be retrieved in
  468. the next synchronization round. */
  469. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  470. inline void
  471. request(const PBGL_DISTRIB_PMAP& pm,
  472. typename PBGL_DISTRIB_PMAP::key_type const& key)
  473. {
  474. if (get(pm.data->global, key).first != process_id(pm.data->process_group))
  475. pm.cell(key, false);
  476. }
  477. /** Get the value associated with a particular key. Retrieves the
  478. * value associated with the given key. If the key denotes a
  479. * locally-owned object, it returns the value from the local property
  480. * map; if the key denotes a remotely-owned object, retrieves the
  481. * value of the ghost cell for that key, which may be the default
  482. * value provided by the reduce operation.
  483. *
  484. * Complexity: For a local key, O(1) get operations on the underlying
  485. * property map. For a non-local key, O(1) accesses to the ghost cells.
  486. */
  487. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  488. inline
  489. typename PBGL_DISTRIB_PMAP::value_type
  490. get(const PBGL_DISTRIB_PMAP& pm,
  491. typename PBGL_DISTRIB_PMAP::key_type const& key)
  492. {
  493. using boost::get;
  494. typename property_traits<GlobalMap>::value_type p =
  495. get(pm.data->global, key);
  496. if (p.first == process_id(pm.data->process_group)) {
  497. return get(pm.data->storage, p.second);
  498. } else {
  499. return pm.cell(key);
  500. }
  501. }
  502. /** Put a value associated with the given key into the property map.
  503. * When the key denotes a locally-owned object, this operation updates
  504. * the underlying local property map. Otherwise, the local ghost cell
  505. * is updated and a "put" message is sent to the processor owning this
  506. * key.
  507. *
  508. * Complexity: For a local key, O(1) put operations on the underlying
  509. * property map. For a nonlocal key, O(1) accesses to the ghost cells
  510. * and will send O(1) messages of size O(sizeof(key) + sizeof(value)).
  511. */
  512. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  513. void
  514. put(const PBGL_DISTRIB_PMAP& pm,
  515. typename PBGL_DISTRIB_PMAP::key_type const & key,
  516. typename PBGL_DISTRIB_PMAP::value_type const & value)
  517. {
  518. using boost::put;
  519. typename property_traits<GlobalMap>::value_type p =
  520. get(pm.data->global, key);
  521. if (p.first == process_id(pm.data->process_group)) {
  522. put(pm.data->storage, p.second, value);
  523. } else {
  524. if (pm.data->model & cm_forward)
  525. pm.request_put(p.first, key, value);
  526. pm.cell(key, false) = value;
  527. }
  528. }
  529. /** Put a value associated with a given key into the local view of the
  530. * property map. This operation is equivalent to @c put, but with one
  531. * exception: no message will be sent to the owning processor in the
  532. * case of a remote update. The effect is that any value written via
  533. * @c local_put for a remote key may be overwritten in the next
  534. * synchronization round.
  535. */
  536. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  537. void
  538. local_put(const PBGL_DISTRIB_PMAP& pm,
  539. typename PBGL_DISTRIB_PMAP::key_type const & key,
  540. typename PBGL_DISTRIB_PMAP::value_type const & value)
  541. {
  542. using boost::put;
  543. typename property_traits<GlobalMap>::value_type p =
  544. get(pm.data->global, key);
  545. if (p.first == process_id(pm.data->process_group))
  546. put(pm.data->storage, p.second, value);
  547. else pm.cell(key, false) = value;
  548. }
  549. /** Cache the value associated with the given remote key. If the key
  550. * is local, ignore the operation. */
  551. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  552. inline void
  553. cache(const PBGL_DISTRIB_PMAP& pm,
  554. typename PBGL_DISTRIB_PMAP::key_type const & key,
  555. typename PBGL_DISTRIB_PMAP::value_type const & value)
  556. {
  557. typename ProcessGroup::process_id_type id = get(pm.data->global, key).first;
  558. if (id != process_id(pm.data->process_group)) pm.cell(key, false) = value;
  559. }
  560. /// Synchronize the property map.
  561. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  562. void
  563. synchronize(PBGL_DISTRIB_PMAP& pm)
  564. {
  565. pm.do_synchronize();
  566. }
  567. /// Create a distributed property map.
  568. template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
  569. inline distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
  570. make_distributed_property_map(const ProcessGroup& pg, GlobalMap global,
  571. StorageMap storage)
  572. {
  573. typedef distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
  574. result_type;
  575. return result_type(pg, global, storage);
  576. }
  577. /**
  578. * \overload
  579. */
  580. template<typename ProcessGroup, typename GlobalMap, typename StorageMap,
  581. typename Reduce>
  582. inline distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
  583. make_distributed_property_map(const ProcessGroup& pg, GlobalMap global,
  584. StorageMap storage, Reduce reduce)
  585. {
  586. typedef distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
  587. result_type;
  588. return result_type(pg, global, storage, reduce);
  589. }
  590. } } // end namespace boost::parallel
  591. // Boost's functional/hash
  592. namespace boost {
  593. template<typename D, typename V>
  594. struct hash<boost::detail::edge_desc_impl<D, V> >
  595. {
  596. std::size_t operator()(const boost::detail::edge_desc_impl<D, V> & x) const
  597. { return hash_value(x.get_property()); }
  598. };
  599. }
  600. #include <boost/property_map/parallel/impl/distributed_property_map.ipp>
  601. #undef PBGL_DISTRIB_PMAP
  602. #endif // BOOST_PARALLEL_DISTRIBUTED_PROPERTY_MAP_HPP