Added boost header
This commit is contained in:
364
test/external/boost/property_map/dynamic_property_map.hpp
vendored
Normal file
364
test/external/boost/property_map/dynamic_property_map.hpp
vendored
Normal file
@@ -0,0 +1,364 @@
|
||||
#ifndef DYNAMIC_PROPERTY_MAP_RG09302004_HPP
|
||||
#define DYNAMIC_PROPERTY_MAP_RG09302004_HPP
|
||||
|
||||
// Copyright 2004-5 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// dynamic_property_map.hpp -
|
||||
// Support for runtime-polymorphic property maps. This header is factored
|
||||
// out of Doug Gregor's routines for reading GraphML files for use in reading
|
||||
// GraphViz graph files.
|
||||
|
||||
// Authors: Doug Gregor
|
||||
// Ronald Garcia
|
||||
//
|
||||
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/function/function3.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <typeinfo>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <boost/type.hpp>
|
||||
#include <boost/smart_ptr.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// read_value -
|
||||
// A wrapper around lexical_cast, which does not behave as
|
||||
// desired for std::string types.
|
||||
template<typename Value>
|
||||
inline Value read_value(const std::string& value)
|
||||
{ return boost::lexical_cast<Value>(value); }
|
||||
|
||||
template<>
|
||||
inline std::string read_value<std::string>(const std::string& value)
|
||||
{ return value; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
// dynamic_property_map -
|
||||
// This interface supports polymorphic manipulation of property maps.
|
||||
class dynamic_property_map
|
||||
{
|
||||
public:
|
||||
virtual ~dynamic_property_map() { }
|
||||
|
||||
virtual boost::any get(const any& key) = 0;
|
||||
virtual std::string get_string(const any& key) = 0;
|
||||
virtual void put(const any& key, const any& value) = 0;
|
||||
virtual const std::type_info& key() const = 0;
|
||||
virtual const std::type_info& value() const = 0;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Property map exceptions
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct dynamic_property_exception : public std::exception {
|
||||
virtual ~dynamic_property_exception() throw() {}
|
||||
virtual const char* what() const throw() = 0;
|
||||
};
|
||||
|
||||
struct property_not_found : public dynamic_property_exception {
|
||||
std::string property;
|
||||
mutable std::string statement;
|
||||
property_not_found(const std::string& property) : property(property) {}
|
||||
virtual ~property_not_found() throw() {}
|
||||
|
||||
const char* what() const throw() {
|
||||
if(statement.empty())
|
||||
statement =
|
||||
std::string("Property not found: ") + property + ".";
|
||||
|
||||
return statement.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
struct dynamic_get_failure : public dynamic_property_exception {
|
||||
std::string property;
|
||||
mutable std::string statement;
|
||||
dynamic_get_failure(const std::string& property) : property(property) {}
|
||||
virtual ~dynamic_get_failure() throw() {}
|
||||
|
||||
const char* what() const throw() {
|
||||
if(statement.empty())
|
||||
statement =
|
||||
std::string(
|
||||
"dynamic property get cannot retrieve value for property: ")
|
||||
+ property + ".";
|
||||
|
||||
return statement.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
struct dynamic_const_put_error : public dynamic_property_exception {
|
||||
virtual ~dynamic_const_put_error() throw() {}
|
||||
|
||||
const char* what() const throw() {
|
||||
return "Attempt to put a value into a const property map: ";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
namespace detail {
|
||||
|
||||
//
|
||||
// dynamic_property_map_adaptor -
|
||||
// property-map adaptor to support runtime polymorphism.
|
||||
template<typename PropertyMap>
|
||||
class dynamic_property_map_adaptor : public dynamic_property_map
|
||||
{
|
||||
typedef typename property_traits<PropertyMap>::key_type key_type;
|
||||
typedef typename property_traits<PropertyMap>::value_type value_type;
|
||||
typedef typename property_traits<PropertyMap>::category category;
|
||||
|
||||
// do_put - overloaded dispatches from the put() member function.
|
||||
// Attempts to "put" to a property map that does not model
|
||||
// WritablePropertyMap result in a runtime exception.
|
||||
|
||||
// in_value must either hold an object of value_type or a string that
|
||||
// can be converted to value_type via iostreams.
|
||||
void do_put(const any& in_key, const any& in_value, mpl::bool_<true>)
|
||||
{
|
||||
#if !(defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95))
|
||||
using boost::put;
|
||||
#endif
|
||||
|
||||
key_type key = any_cast<key_type>(in_key);
|
||||
if (in_value.type() == typeid(value_type)) {
|
||||
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
|
||||
boost::put(property_map, key, any_cast<value_type>(in_value));
|
||||
#else
|
||||
put(property_map, key, any_cast<value_type>(in_value));
|
||||
#endif
|
||||
} else {
|
||||
// if in_value is an empty string, put a default constructed value_type.
|
||||
std::string v = any_cast<std::string>(in_value);
|
||||
if (v.empty()) {
|
||||
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
|
||||
boost::put(property_map, key, value_type());
|
||||
#else
|
||||
put(property_map, key, value_type());
|
||||
#endif
|
||||
} else {
|
||||
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
|
||||
boost::put(property_map, key, detail::read_value<value_type>(v));
|
||||
#else
|
||||
put(property_map, key, detail::read_value<value_type>(v));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void do_put(const any&, const any&, mpl::bool_<false>)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(dynamic_const_put_error());
|
||||
}
|
||||
|
||||
public:
|
||||
explicit dynamic_property_map_adaptor(const PropertyMap& property_map)
|
||||
: property_map(property_map) { }
|
||||
|
||||
virtual boost::any get(const any& key)
|
||||
{
|
||||
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
|
||||
return boost::get(property_map, any_cast<key_type>(key));
|
||||
#else
|
||||
using boost::get;
|
||||
|
||||
return get(property_map, any_cast<key_type>(key));
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual std::string get_string(const any& key)
|
||||
{
|
||||
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
|
||||
std::ostringstream out;
|
||||
out << boost::get(property_map, any_cast<key_type>(key));
|
||||
return out.str();
|
||||
#else
|
||||
using boost::get;
|
||||
|
||||
std::ostringstream out;
|
||||
out << get(property_map, any_cast<key_type>(key));
|
||||
return out.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void put(const any& in_key, const any& in_value)
|
||||
{
|
||||
do_put(in_key, in_value,
|
||||
mpl::bool_<(is_convertible<category*,
|
||||
writable_property_map_tag*>::value)>());
|
||||
}
|
||||
|
||||
virtual const std::type_info& key() const { return typeid(key_type); }
|
||||
virtual const std::type_info& value() const { return typeid(value_type); }
|
||||
|
||||
PropertyMap& base() { return property_map; }
|
||||
const PropertyMap& base() const { return property_map; }
|
||||
|
||||
private:
|
||||
PropertyMap property_map;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// dynamic_properties -
|
||||
// container for dynamic property maps
|
||||
//
|
||||
struct dynamic_properties
|
||||
{
|
||||
typedef std::multimap<std::string, boost::shared_ptr<dynamic_property_map> >
|
||||
property_maps_type;
|
||||
typedef boost::function3<boost::shared_ptr<dynamic_property_map>,
|
||||
const std::string&,
|
||||
const boost::any&,
|
||||
const boost::any&> generate_fn_type;
|
||||
public:
|
||||
|
||||
typedef property_maps_type::iterator iterator;
|
||||
typedef property_maps_type::const_iterator const_iterator;
|
||||
|
||||
dynamic_properties() : generate_fn() { }
|
||||
dynamic_properties(const generate_fn_type& g) : generate_fn(g) {}
|
||||
|
||||
~dynamic_properties() {}
|
||||
|
||||
template<typename PropertyMap>
|
||||
dynamic_properties&
|
||||
property(const std::string& name, PropertyMap property_map)
|
||||
{
|
||||
// Tbd: exception safety
|
||||
boost::shared_ptr<dynamic_property_map> pm(
|
||||
new detail::dynamic_property_map_adaptor<PropertyMap>(property_map));
|
||||
property_maps.insert(property_maps_type::value_type(name, pm));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
iterator begin() { return property_maps.begin(); }
|
||||
const_iterator begin() const { return property_maps.begin(); }
|
||||
iterator end() { return property_maps.end(); }
|
||||
const_iterator end() const { return property_maps.end(); }
|
||||
|
||||
iterator lower_bound(const std::string& name)
|
||||
{ return property_maps.lower_bound(name); }
|
||||
|
||||
const_iterator lower_bound(const std::string& name) const
|
||||
{ return property_maps.lower_bound(name); }
|
||||
|
||||
void
|
||||
insert(const std::string& name, boost::shared_ptr<dynamic_property_map> pm)
|
||||
{
|
||||
property_maps.insert(property_maps_type::value_type(name, pm));
|
||||
}
|
||||
|
||||
template<typename Key, typename Value>
|
||||
boost::shared_ptr<dynamic_property_map>
|
||||
generate(const std::string& name, const Key& key, const Value& value)
|
||||
{
|
||||
if(!generate_fn) {
|
||||
BOOST_THROW_EXCEPTION(property_not_found(name));
|
||||
} else {
|
||||
return generate_fn(name,key,value);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
property_maps_type property_maps;
|
||||
generate_fn_type generate_fn;
|
||||
};
|
||||
|
||||
template<typename Key, typename Value>
|
||||
bool
|
||||
put(const std::string& name, dynamic_properties& dp, const Key& key,
|
||||
const Value& value)
|
||||
{
|
||||
for (dynamic_properties::iterator i = dp.lower_bound(name);
|
||||
i != dp.end() && i->first == name; ++i) {
|
||||
if (i->second->key() == typeid(key)) {
|
||||
i->second->put(key, value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
boost::shared_ptr<dynamic_property_map> new_map = dp.generate(name, key, value);
|
||||
if (new_map.get()) {
|
||||
new_map->put(key, value);
|
||||
dp.insert(name, new_map);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS
|
||||
template<typename Value, typename Key>
|
||||
Value
|
||||
get(const std::string& name, const dynamic_properties& dp, const Key& key)
|
||||
{
|
||||
for (dynamic_properties::const_iterator i = dp.lower_bound(name);
|
||||
i != dp.end() && i->first == name; ++i) {
|
||||
if (i->second->key() == typeid(key))
|
||||
return any_cast<Value>(i->second->get(key));
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(dynamic_get_failure(name));
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename Value, typename Key>
|
||||
Value
|
||||
get(const std::string& name, const dynamic_properties& dp, const Key& key, type<Value>)
|
||||
{
|
||||
for (dynamic_properties::const_iterator i = dp.lower_bound(name);
|
||||
i != dp.end() && i->first == name; ++i) {
|
||||
if (i->second->key() == typeid(key))
|
||||
return any_cast<Value>(i->second->get(key));
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(dynamic_get_failure(name));
|
||||
}
|
||||
|
||||
template<typename Key>
|
||||
std::string
|
||||
get(const std::string& name, const dynamic_properties& dp, const Key& key)
|
||||
{
|
||||
for (dynamic_properties::const_iterator i = dp.lower_bound(name);
|
||||
i != dp.end() && i->first == name; ++i) {
|
||||
if (i->second->key() == typeid(key))
|
||||
return i->second->get_string(key);
|
||||
}
|
||||
|
||||
BOOST_THROW_EXCEPTION(dynamic_get_failure(name));
|
||||
}
|
||||
|
||||
// The easy way to ignore properties.
|
||||
inline
|
||||
boost::shared_ptr<boost::dynamic_property_map>
|
||||
ignore_other_properties(const std::string&,
|
||||
const boost::any&,
|
||||
const boost::any&) {
|
||||
return boost::shared_ptr<boost::dynamic_property_map>();
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // DYNAMIC_PROPERTY_MAP_RG09302004_HPP
|
||||
96
test/external/boost/property_map/parallel/caching_property_map.hpp
vendored
Normal file
96
test/external/boost/property_map/parallel/caching_property_map.hpp
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright 2004 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Authors: Douglas Gregor
|
||||
// Andrew Lumsdaine
|
||||
#ifndef BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
|
||||
#define BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
|
||||
|
||||
#ifndef BOOST_GRAPH_USE_MPI
|
||||
#error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
|
||||
#endif
|
||||
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// This probably doesn't belong here
|
||||
template<typename Key, typename Value>
|
||||
inline void local_put(dummy_property_map, const Key&, const Value&) {}
|
||||
|
||||
namespace parallel {
|
||||
|
||||
/** Property map that caches values placed in it but does not
|
||||
* broadcast values to remote processors. This class template is
|
||||
* meant as an adaptor for @ref distributed_property_map that
|
||||
* suppresses communication in the event of a remote @c put operation
|
||||
* by mapping it to a local @c put operation.
|
||||
*
|
||||
* @todo Find a better name for @ref caching_property_map
|
||||
*/
|
||||
template<typename PropertyMap>
|
||||
class caching_property_map
|
||||
{
|
||||
public:
|
||||
typedef typename property_traits<PropertyMap>::key_type key_type;
|
||||
typedef typename property_traits<PropertyMap>::value_type value_type;
|
||||
typedef typename property_traits<PropertyMap>::reference reference;
|
||||
typedef typename property_traits<PropertyMap>::category category;
|
||||
|
||||
explicit caching_property_map(const PropertyMap& property_map)
|
||||
: property_map(property_map) {}
|
||||
|
||||
PropertyMap& base() { return property_map; }
|
||||
const PropertyMap& base() const { return property_map; }
|
||||
|
||||
template<typename Reduce>
|
||||
void set_reduce(const Reduce& reduce)
|
||||
{ property_map.set_reduce(reduce); }
|
||||
|
||||
void reset() { property_map.reset(); }
|
||||
|
||||
#if 0
|
||||
reference operator[](const key_type& key) const
|
||||
{
|
||||
return property_map[key];
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
PropertyMap property_map;
|
||||
};
|
||||
|
||||
template<typename PropertyMap, typename Key>
|
||||
inline typename caching_property_map<PropertyMap>::value_type
|
||||
get(const caching_property_map<PropertyMap>& pm, const Key& key)
|
||||
{ return get(pm.base(), key); }
|
||||
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
inline void
|
||||
local_put(const caching_property_map<PropertyMap>& pm, const Key& key,
|
||||
const Value& value)
|
||||
{ local_put(pm.base(), key, value); }
|
||||
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
inline void
|
||||
cache(const caching_property_map<PropertyMap>& pm, const Key& key,
|
||||
const Value& value)
|
||||
{ cache(pm.base(), key, value); }
|
||||
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
inline void
|
||||
put(const caching_property_map<PropertyMap>& pm, const Key& key,
|
||||
const Value& value)
|
||||
{ local_put(pm.base(), key, value); }
|
||||
|
||||
template<typename PropertyMap>
|
||||
inline caching_property_map<PropertyMap>
|
||||
make_caching_property_map(const PropertyMap& pm)
|
||||
{ return caching_property_map<PropertyMap>(pm); }
|
||||
|
||||
} } // end namespace boost::parallel
|
||||
|
||||
#endif // BOOST_PARALLEL_CACHING_PROPERTY_MAP_HPP
|
||||
710
test/external/boost/property_map/parallel/distributed_property_map.hpp
vendored
Normal file
710
test/external/boost/property_map/parallel/distributed_property_map.hpp
vendored
Normal file
@@ -0,0 +1,710 @@
|
||||
// Copyright (C) 2004-2008 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Authors: Douglas Gregor
|
||||
// Nick Edmonds
|
||||
// Andrew Lumsdaine
|
||||
|
||||
// The placement of this #include probably looks very odd relative to
|
||||
// the #ifndef/#define pair below. However, this placement is
|
||||
// extremely important to allow the various property map headers to be
|
||||
// included in any order.
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
|
||||
#ifndef BOOST_PARALLEL_DISTRIBUTED_PROPERTY_MAP_HPP
|
||||
#define BOOST_PARALLEL_DISTRIBUTED_PROPERTY_MAP_HPP
|
||||
|
||||
#ifndef BOOST_GRAPH_USE_MPI
|
||||
#error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
|
||||
#endif
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/graph/parallel/process_group.hpp>
|
||||
#include <boost/graph/detail/edge.hpp>
|
||||
#include <boost/function/function1.hpp>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <boost/graph/parallel/basic_reduce.hpp>
|
||||
#include <boost/graph/parallel/detail/untracked_pair.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/property_map/parallel/local_property_map.hpp>
|
||||
#include <map>
|
||||
#include <boost/version.hpp>
|
||||
#include <boost/graph/distributed/unsafe_serialize.hpp>
|
||||
#include <boost/multi_index_container.hpp>
|
||||
#include <boost/multi_index/hashed_index.hpp>
|
||||
#include <boost/multi_index/member.hpp>
|
||||
#include <boost/multi_index/sequenced_index.hpp>
|
||||
|
||||
// Serialization functions for constructs we use
|
||||
#include <boost/serialization/utility.hpp>
|
||||
|
||||
namespace boost { namespace parallel {
|
||||
|
||||
using boost::graph::parallel::trigger_receive_context;
|
||||
|
||||
namespace detail {
|
||||
/**************************************************************************
|
||||
* Metafunction that degrades an Lvalue Property Map category tag to
|
||||
* a Read Write Property Map category tag.
|
||||
**************************************************************************/
|
||||
template<bool IsLvaluePropertyMap>
|
||||
struct make_nonlvalue_property_map
|
||||
{
|
||||
template<typename T> struct apply { typedef T type; };
|
||||
};
|
||||
|
||||
template<>
|
||||
struct make_nonlvalue_property_map<true>
|
||||
{
|
||||
template<typename>
|
||||
struct apply
|
||||
{
|
||||
typedef read_write_property_map_tag type;
|
||||
};
|
||||
};
|
||||
|
||||
/**************************************************************************
|
||||
* Performs a "put" on a property map so long as the property map is
|
||||
* a Writable Property Map or a mutable Lvalue Property Map. This
|
||||
* is required because the distributed property map's message
|
||||
* handler handles "put" messages even for a const property map,
|
||||
* although receipt of a "put" message is ill-formed.
|
||||
**************************************************************************/
|
||||
template<bool IsLvaluePropertyMap>
|
||||
struct maybe_put_in_lvalue_pm
|
||||
{
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
static inline void
|
||||
do_put(PropertyMap, const Key&, const Value&)
|
||||
{ BOOST_ASSERT(false); }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct maybe_put_in_lvalue_pm<true>
|
||||
{
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
static inline void
|
||||
do_put(PropertyMap pm, const Key& key, const Value& value)
|
||||
{
|
||||
using boost::put;
|
||||
|
||||
put(pm, key, value);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
inline void
|
||||
maybe_put_impl(PropertyMap pm, const Key& key, const Value& value,
|
||||
writable_property_map_tag)
|
||||
{
|
||||
using boost::put;
|
||||
|
||||
put(pm, key, value);
|
||||
}
|
||||
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
inline void
|
||||
maybe_put_impl(PropertyMap pm, const Key& key, const Value& value,
|
||||
lvalue_property_map_tag)
|
||||
{
|
||||
typedef typename property_traits<PropertyMap>::value_type value_type;
|
||||
typedef typename property_traits<PropertyMap>::reference reference;
|
||||
// DPG TBD: Some property maps are improperly characterized as
|
||||
// lvalue_property_maps, when in fact they do not provide true
|
||||
// references. The most typical example is those property maps
|
||||
// built from vector<bool> and its iterators, which deal with
|
||||
// proxies. We don't want to mischaracterize these as not having a
|
||||
// "put" operation, so we only consider an lvalue_property_map as
|
||||
// constant if its reference is const value_type&. In fact, this
|
||||
// isn't even quite correct (think of a
|
||||
// vector<bool>::const_iterator), but at present C++ doesn't
|
||||
// provide us with any alternatives.
|
||||
typedef is_same<const value_type&, reference> is_constant;
|
||||
|
||||
maybe_put_in_lvalue_pm<(!is_constant::value)>::do_put(pm, key, value);
|
||||
}
|
||||
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
inline void
|
||||
maybe_put_impl(PropertyMap, const Key&, const Value&, ...)
|
||||
{ BOOST_ASSERT(false); }
|
||||
|
||||
template<typename PropertyMap, typename Key, typename Value>
|
||||
inline void
|
||||
maybe_put(PropertyMap pm, const Key& key, const Value& value)
|
||||
{
|
||||
maybe_put_impl(pm, key, value,
|
||||
typename property_traits<PropertyMap>::category());
|
||||
}
|
||||
} // end namespace detail
|
||||
|
||||
/** The consistency model used by the distributed property map. */
|
||||
enum consistency_model {
|
||||
cm_forward = 1 << 0,
|
||||
cm_backward = 1 << 1,
|
||||
cm_bidirectional = cm_forward | cm_backward,
|
||||
cm_flush = 1 << 2,
|
||||
cm_reset = 1 << 3,
|
||||
cm_clear = 1 << 4
|
||||
};
|
||||
|
||||
/** Distributed property map adaptor.
|
||||
*
|
||||
* The distributed property map adaptor is a property map whose
|
||||
* stored values are distributed across multiple non-overlapping
|
||||
* memory spaces on different processes. Values local to the current
|
||||
* process are stored within a local property map and may be
|
||||
* immediately accessed via @c get and @c put. Values stored on
|
||||
* remote processes may also be access via @c get and @c put, but the
|
||||
* behavior differs slightly:
|
||||
*
|
||||
* - @c put operations update a local ghost cell and send a "put"
|
||||
* message to the process that owns the value. The owner is free to
|
||||
* update its own "official" value or may ignore the put request.
|
||||
*
|
||||
* - @c get operations returns the contents of the local ghost
|
||||
* cell. If no ghost cell is available, one is created using the
|
||||
* default value provided by the "reduce" operation. See, e.g.,
|
||||
* @ref basic_reduce and @ref property_reduce.
|
||||
*
|
||||
* Using distributed property maps requires a bit more care than using
|
||||
* local, sequential property maps. While the syntax and semantics are
|
||||
* similar, distributed property maps may contain out-of-date
|
||||
* information that can only be guaranteed to be synchronized by
|
||||
* calling the @ref synchronize function in all processes.
|
||||
*
|
||||
* To address the issue of out-of-date values, distributed property
|
||||
* maps are supplied with a reduction operation. The reduction
|
||||
* operation has two roles:
|
||||
*
|
||||
* -# When a value is needed for a remote key but no value is
|
||||
* immediately available, the reduction operation provides a
|
||||
* suitable default. For instance, a distributed property map
|
||||
* storing distances may have a reduction operation that returns
|
||||
* an infinite value as the default, whereas a distributed
|
||||
* property map for vertex colors may return white as the
|
||||
* default.
|
||||
*
|
||||
* -# When a value is received from a remote process, the process
|
||||
* owning the key associated with that value must determine which
|
||||
* value---the locally stored value, the value received from a
|
||||
* remote process, or some combination of the two---will be
|
||||
* stored as the "official" value in the property map. The
|
||||
* reduction operation transforms the local and remote values
|
||||
* into the "official" value to be stored.
|
||||
*
|
||||
* @tparam ProcessGroup the type of the process group over which the
|
||||
* property map is distributed and is also the medium for
|
||||
* communication.
|
||||
*
|
||||
* @tparam StorageMap the type of the property map that will
|
||||
* store values for keys local to this processor. The @c value_type of
|
||||
* this property map will become the @c value_type of the distributed
|
||||
* property map. The distributed property map models the same property
|
||||
* map concepts as the @c LocalPropertyMap, with one exception: a
|
||||
* distributed property map cannot be an LvaluePropertyMap (because
|
||||
* remote values are not addressable), and is therefore limited to
|
||||
* ReadWritePropertyMap.
|
||||
*/
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
class distributed_property_map
|
||||
{
|
||||
public:
|
||||
/// The key type of the property map.
|
||||
typedef typename property_traits<GlobalMap>::key_type key_type;
|
||||
|
||||
/// The value type of the property map.
|
||||
typedef typename property_traits<StorageMap>::value_type value_type;
|
||||
typedef typename property_traits<StorageMap>::reference reference;
|
||||
typedef ProcessGroup process_group_type;
|
||||
|
||||
private:
|
||||
typedef distributed_property_map self_type;
|
||||
typedef typename property_traits<StorageMap>::category local_category;
|
||||
typedef typename property_traits<StorageMap>::key_type local_key_type;
|
||||
typedef typename property_traits<GlobalMap>::value_type owner_local_pair;
|
||||
typedef typename ProcessGroup::process_id_type process_id_type;
|
||||
|
||||
enum property_map_messages {
|
||||
/** A request to store a value in a property map. The message
|
||||
* contains a std::pair<key, data>.
|
||||
*/
|
||||
property_map_put,
|
||||
|
||||
/** A request to retrieve a particular value in a property
|
||||
* map. The message contains a key. The owner of that key will
|
||||
* reply with a value.
|
||||
*/
|
||||
property_map_get,
|
||||
|
||||
/** A request to update values stored on a remote processor. The
|
||||
* message contains a vector of keys for which the source
|
||||
* requests updated values. This message will only be transmitted
|
||||
* during synchronization.
|
||||
*/
|
||||
property_map_multiget,
|
||||
|
||||
/** A request to store values in a ghost cell. This message
|
||||
* contains a vector of key/value pairs corresponding to the
|
||||
* sequence of keys sent to the source processor.
|
||||
*/
|
||||
property_map_multiget_reply,
|
||||
|
||||
/** The payload containing a vector of local key-value pairs to be
|
||||
* put into the remote property map. A key-value std::pair will be
|
||||
* used to store each local key-value pair.
|
||||
*/
|
||||
property_map_multiput
|
||||
};
|
||||
|
||||
// Code from Joaquín M López Muñoz to work around unusual implementation of
|
||||
// std::pair in VC++ 10:
|
||||
template<typename First,typename Second>
|
||||
class pair_first_extractor {
|
||||
typedef std::pair<First,Second> value_type;
|
||||
|
||||
public:
|
||||
typedef First result_type;
|
||||
const result_type& operator()(const value_type& x) const {
|
||||
return x.first;
|
||||
}
|
||||
|
||||
result_type& operator()(value_type& x) const {
|
||||
return x.first;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
/// The type of the ghost cells
|
||||
typedef multi_index::multi_index_container<
|
||||
std::pair<key_type, value_type>,
|
||||
multi_index::indexed_by<
|
||||
multi_index::sequenced<>,
|
||||
multi_index::hashed_unique<
|
||||
pair_first_extractor<key_type, value_type>
|
||||
>
|
||||
>
|
||||
> ghost_cells_type;
|
||||
|
||||
/// Iterator into the ghost cells
|
||||
typedef typename ghost_cells_type::iterator iterator;
|
||||
|
||||
/// Key-based index into the ghost cells
|
||||
typedef typename ghost_cells_type::template nth_index<1>::type
|
||||
ghost_cells_key_index_type;
|
||||
|
||||
/// Iterator into the ghost cells (by key)
|
||||
typedef typename ghost_cells_key_index_type::iterator key_iterator;
|
||||
|
||||
/** The property map category. A distributed property map cannot be
|
||||
* an Lvalue Property Map, because values on remote processes cannot
|
||||
* be addresses.
|
||||
*/
|
||||
typedef typename detail::make_nonlvalue_property_map<
|
||||
(is_base_and_derived<lvalue_property_map_tag, local_category>::value
|
||||
|| is_same<lvalue_property_map_tag, local_category>::value)>
|
||||
::template apply<local_category>::type category;
|
||||
|
||||
/** Default-construct a distributed property map. This function
|
||||
* creates an initialized property map that must be assigned to a
|
||||
* valid value before being used. It is only provided here because
|
||||
* property maps must be Default Constructible.
|
||||
*/
|
||||
distributed_property_map() {}
|
||||
|
||||
/** Construct a distributed property map. Builds a distributed
|
||||
* property map communicating over the given process group and using
|
||||
* the given local property map for storage. Since no reduction
|
||||
* operation is provided, the default reduction operation @c
|
||||
* basic_reduce<value_type> is used.
|
||||
*/
|
||||
distributed_property_map(const ProcessGroup& pg, const GlobalMap& global,
|
||||
const StorageMap& pm)
|
||||
: data(new data_t(pg, global, pm, basic_reduce<value_type>(), false))
|
||||
{
|
||||
typedef handle_message<basic_reduce<value_type> > Handler;
|
||||
|
||||
data->ghost_cells.reset(new ghost_cells_type());
|
||||
Handler handler(data);
|
||||
data->process_group.replace_handler(handler, true);
|
||||
data->process_group.template get_receiver<Handler>()
|
||||
->setup_triggers(data->process_group);
|
||||
}
|
||||
|
||||
/** Construct a distributed property map. Builds a distributed
|
||||
* property map communicating over the given process group and using
|
||||
* the given local property map for storage. The given @p reduce
|
||||
* parameter is used as the reduction operation.
|
||||
*/
|
||||
template<typename Reduce>
|
||||
distributed_property_map(const ProcessGroup& pg, const GlobalMap& global,
|
||||
const StorageMap& pm,
|
||||
const Reduce& reduce);
|
||||
|
||||
~distributed_property_map();
|
||||
|
||||
/// Set the reduce operation of the distributed property map.
|
||||
template<typename Reduce>
|
||||
void set_reduce(const Reduce& reduce);
|
||||
|
||||
// Set the consistency model for the distributed property map
|
||||
void set_consistency_model(int model);
|
||||
|
||||
// Get the consistency model
|
||||
int get_consistency_model() const { return data->model; }
|
||||
|
||||
// Set the maximum number of ghost cells that we are allowed to
|
||||
// maintain. If 0, all ghost cells will be retained.
|
||||
void set_max_ghost_cells(std::size_t max_ghost_cells);
|
||||
|
||||
// Clear out all ghost cells
|
||||
void clear();
|
||||
|
||||
// Reset the values in all ghost cells to the default value
|
||||
void reset();
|
||||
|
||||
// Flush all values destined for remote processors
|
||||
void flush();
|
||||
|
||||
reference operator[](const key_type& key) const
|
||||
{
|
||||
owner_local_pair p = get(data->global, key);
|
||||
|
||||
if (p.first == process_id(data->process_group)) {
|
||||
return data->storage[p.second];
|
||||
} else {
|
||||
return cell(key);
|
||||
}
|
||||
}
|
||||
|
||||
process_group_type process_group() const
|
||||
{
|
||||
return data->process_group.base();
|
||||
}
|
||||
|
||||
StorageMap& base() { return data->storage; }
|
||||
const StorageMap& base() const { return data->storage; }
|
||||
|
||||
/** Sends a "put" request.
|
||||
* \internal
|
||||
*
|
||||
*/
|
||||
void
|
||||
request_put(process_id_type p, const key_type& k, const value_type& v) const
|
||||
{
|
||||
send(data->process_group, p, property_map_put,
|
||||
boost::parallel::detail::make_untracked_pair(k, v));
|
||||
}
|
||||
|
||||
/** Access the ghost cell for the given key.
|
||||
* \internal
|
||||
*/
|
||||
value_type& cell(const key_type& k, bool request_if_missing = true) const;
|
||||
|
||||
/** Perform synchronization
|
||||
* \internal
|
||||
*/
|
||||
void do_synchronize();
|
||||
|
||||
const GlobalMap& global() const { return data->global; }
|
||||
GlobalMap& global() { return data->global; }
|
||||
|
||||
struct data_t
|
||||
{
|
||||
data_t(const ProcessGroup& pg, const GlobalMap& global,
|
||||
const StorageMap& pm, const function1<value_type, key_type>& dv,
|
||||
bool has_default_resolver)
|
||||
: process_group(pg), global(global), storage(pm),
|
||||
ghost_cells(), max_ghost_cells(1000000), get_default_value(dv),
|
||||
has_default_resolver(has_default_resolver), model(cm_forward) { }
|
||||
|
||||
/// The process group
|
||||
ProcessGroup process_group;
|
||||
|
||||
/// A mapping from the keys of this property map to the global
|
||||
/// descriptor.
|
||||
GlobalMap global;
|
||||
|
||||
/// Local property map
|
||||
StorageMap storage;
|
||||
|
||||
/// The ghost cells
|
||||
shared_ptr<ghost_cells_type> ghost_cells;
|
||||
|
||||
/// The maximum number of ghost cells we are permitted to hold. If
|
||||
/// zero, we are permitted to have an infinite number of ghost
|
||||
/// cells.
|
||||
std::size_t max_ghost_cells;
|
||||
|
||||
/// Default value for remote ghost cells, as defined by the
|
||||
/// reduction operation.
|
||||
function1<value_type, key_type> get_default_value;
|
||||
|
||||
/// True if this resolver is the "default" resolver, meaning that
|
||||
/// we should not be able to get() a default value; it needs to be
|
||||
/// request()ed first.
|
||||
bool has_default_resolver;
|
||||
|
||||
// Current consistency model
|
||||
int model;
|
||||
|
||||
// Function that resets all of the ghost cells to their default
|
||||
// values. It knows the type of the resolver, so we can eliminate
|
||||
// a large number of calls through function pointers.
|
||||
void (data_t::*reset)();
|
||||
|
||||
// Clear out all ghost cells
|
||||
void clear();
|
||||
|
||||
// Flush all values destined for remote processors
|
||||
void flush();
|
||||
|
||||
// Send out requests to "refresh" the values of ghost cells that
|
||||
// we're holding.
|
||||
void refresh_ghost_cells();
|
||||
|
||||
private:
|
||||
template<typename Resolver> void do_reset();
|
||||
|
||||
friend class distributed_property_map;
|
||||
};
|
||||
friend struct data_t;
|
||||
|
||||
shared_ptr<data_t> data;
|
||||
|
||||
private:
|
||||
// Prunes the least recently used ghost cells until we have @c
|
||||
// max_ghost_cells or fewer ghost cells.
|
||||
void prune_ghost_cells() const;
|
||||
|
||||
/** Handles incoming messages.
|
||||
*
|
||||
* This function object is responsible for handling all incoming
|
||||
* messages for the distributed property map.
|
||||
*/
|
||||
template<typename Reduce>
|
||||
struct handle_message
|
||||
{
|
||||
explicit handle_message(const shared_ptr<data_t>& data,
|
||||
const Reduce& reduce = Reduce())
|
||||
: data_ptr(data), reduce(reduce) { }
|
||||
|
||||
void operator()(process_id_type source, int tag);
|
||||
|
||||
/// Individual message handlers
|
||||
void
|
||||
handle_put(int source, int tag,
|
||||
const boost::parallel::detail::untracked_pair<key_type, value_type>& data,
|
||||
trigger_receive_context);
|
||||
|
||||
value_type
|
||||
handle_get(int source, int tag, const key_type& data,
|
||||
trigger_receive_context);
|
||||
|
||||
void
|
||||
handle_multiget(int source, int tag,
|
||||
const std::vector<key_type>& data,
|
||||
trigger_receive_context);
|
||||
|
||||
void
|
||||
handle_multiget_reply
|
||||
(int source, int tag,
|
||||
const std::vector<boost::parallel::detail::untracked_pair<key_type, value_type> >& msg,
|
||||
trigger_receive_context);
|
||||
|
||||
void
|
||||
handle_multiput
|
||||
(int source, int tag,
|
||||
const std::vector<unsafe_pair<local_key_type, value_type> >& data,
|
||||
trigger_receive_context);
|
||||
|
||||
void setup_triggers(process_group_type& pg);
|
||||
|
||||
private:
|
||||
weak_ptr<data_t> data_ptr;
|
||||
Reduce reduce;
|
||||
};
|
||||
|
||||
/* Sets up the next stage in a multi-stage synchronization, for
|
||||
bidirectional consistency. */
|
||||
struct on_synchronize
|
||||
{
|
||||
explicit on_synchronize(const shared_ptr<data_t>& data) : data_ptr(data) { }
|
||||
|
||||
void operator()();
|
||||
|
||||
private:
|
||||
weak_ptr<data_t> data_ptr;
|
||||
};
|
||||
};
|
||||
|
||||
/* An implementation helper macro for the common case of naming
|
||||
distributed property maps with all of the normal template
|
||||
parameters. */
|
||||
#define PBGL_DISTRIB_PMAP \
|
||||
distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
|
||||
/* Request that the value for the given remote key be retrieved in
|
||||
the next synchronization round. */
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
inline void
|
||||
request(const PBGL_DISTRIB_PMAP& pm,
|
||||
typename PBGL_DISTRIB_PMAP::key_type const& key)
|
||||
{
|
||||
if (get(pm.data->global, key).first != process_id(pm.data->process_group))
|
||||
pm.cell(key, false);
|
||||
}
|
||||
|
||||
/** Get the value associated with a particular key. Retrieves the
|
||||
* value associated with the given key. If the key denotes a
|
||||
* locally-owned object, it returns the value from the local property
|
||||
* map; if the key denotes a remotely-owned object, retrieves the
|
||||
* value of the ghost cell for that key, which may be the default
|
||||
* value provided by the reduce operation.
|
||||
*
|
||||
* Complexity: For a local key, O(1) get operations on the underlying
|
||||
* property map. For a non-local key, O(1) accesses to the ghost cells.
|
||||
*/
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
inline
|
||||
typename PBGL_DISTRIB_PMAP::value_type
|
||||
get(const PBGL_DISTRIB_PMAP& pm,
|
||||
typename PBGL_DISTRIB_PMAP::key_type const& key)
|
||||
{
|
||||
using boost::get;
|
||||
|
||||
typename property_traits<GlobalMap>::value_type p =
|
||||
get(pm.data->global, key);
|
||||
|
||||
if (p.first == process_id(pm.data->process_group)) {
|
||||
return get(pm.data->storage, p.second);
|
||||
} else {
|
||||
return pm.cell(key);
|
||||
}
|
||||
}
|
||||
|
||||
/** Put a value associated with the given key into the property map.
|
||||
* When the key denotes a locally-owned object, this operation updates
|
||||
* the underlying local property map. Otherwise, the local ghost cell
|
||||
* is updated and a "put" message is sent to the processor owning this
|
||||
* key.
|
||||
*
|
||||
* Complexity: For a local key, O(1) put operations on the underlying
|
||||
* property map. For a nonlocal key, O(1) accesses to the ghost cells
|
||||
* and will send O(1) messages of size O(sizeof(key) + sizeof(value)).
|
||||
*/
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void
|
||||
put(const PBGL_DISTRIB_PMAP& pm,
|
||||
typename PBGL_DISTRIB_PMAP::key_type const & key,
|
||||
typename PBGL_DISTRIB_PMAP::value_type const & value)
|
||||
{
|
||||
using boost::put;
|
||||
|
||||
typename property_traits<GlobalMap>::value_type p =
|
||||
get(pm.data->global, key);
|
||||
|
||||
if (p.first == process_id(pm.data->process_group)) {
|
||||
put(pm.data->storage, p.second, value);
|
||||
} else {
|
||||
if (pm.data->model & cm_forward)
|
||||
pm.request_put(p.first, key, value);
|
||||
|
||||
pm.cell(key, false) = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Put a value associated with a given key into the local view of the
|
||||
* property map. This operation is equivalent to @c put, but with one
|
||||
* exception: no message will be sent to the owning processor in the
|
||||
* case of a remote update. The effect is that any value written via
|
||||
* @c local_put for a remote key may be overwritten in the next
|
||||
* synchronization round.
|
||||
*/
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void
|
||||
local_put(const PBGL_DISTRIB_PMAP& pm,
|
||||
typename PBGL_DISTRIB_PMAP::key_type const & key,
|
||||
typename PBGL_DISTRIB_PMAP::value_type const & value)
|
||||
{
|
||||
using boost::put;
|
||||
|
||||
typename property_traits<GlobalMap>::value_type p =
|
||||
get(pm.data->global, key);
|
||||
|
||||
if (p.first == process_id(pm.data->process_group))
|
||||
put(pm.data->storage, p.second, value);
|
||||
else pm.cell(key, false) = value;
|
||||
}
|
||||
|
||||
/** Cache the value associated with the given remote key. If the key
|
||||
* is local, ignore the operation. */
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
inline void
|
||||
cache(const PBGL_DISTRIB_PMAP& pm,
|
||||
typename PBGL_DISTRIB_PMAP::key_type const & key,
|
||||
typename PBGL_DISTRIB_PMAP::value_type const & value)
|
||||
{
|
||||
typename ProcessGroup::process_id_type id = get(pm.data->global, key).first;
|
||||
|
||||
if (id != process_id(pm.data->process_group)) pm.cell(key, false) = value;
|
||||
}
|
||||
|
||||
/// Synchronize the property map.
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void
|
||||
synchronize(PBGL_DISTRIB_PMAP& pm)
|
||||
{
|
||||
pm.do_synchronize();
|
||||
}
|
||||
|
||||
/// Create a distributed property map.
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
inline distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
make_distributed_property_map(const ProcessGroup& pg, GlobalMap global,
|
||||
StorageMap storage)
|
||||
{
|
||||
typedef distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
result_type;
|
||||
return result_type(pg, global, storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* \overload
|
||||
*/
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap,
|
||||
typename Reduce>
|
||||
inline distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
make_distributed_property_map(const ProcessGroup& pg, GlobalMap global,
|
||||
StorageMap storage, Reduce reduce)
|
||||
{
|
||||
typedef distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
result_type;
|
||||
return result_type(pg, global, storage, reduce);
|
||||
}
|
||||
|
||||
} } // end namespace boost::parallel
|
||||
|
||||
// Boost's functional/hash
|
||||
namespace boost {
|
||||
template<typename D, typename V>
|
||||
struct hash<boost::detail::edge_desc_impl<D, V> >
|
||||
{
|
||||
std::size_t operator()(const boost::detail::edge_desc_impl<D, V> & x) const
|
||||
{ return hash_value(x.get_property()); }
|
||||
};
|
||||
}
|
||||
|
||||
#include <boost/property_map/parallel/impl/distributed_property_map.ipp>
|
||||
|
||||
#undef PBGL_DISTRIB_PMAP
|
||||
|
||||
#endif // BOOST_PARALLEL_DISTRIBUTED_PROPERTY_MAP_HPP
|
||||
74
test/external/boost/property_map/parallel/global_index_map.hpp
vendored
Normal file
74
test/external/boost/property_map/parallel/global_index_map.hpp
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
// Copyright 2005 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Authors: Douglas Gregor
|
||||
// Andrew Lumsdaine
|
||||
#ifndef BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP
|
||||
#define BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP
|
||||
|
||||
#ifndef BOOST_GRAPH_USE_MPI
|
||||
#error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
|
||||
#endif
|
||||
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
#include <vector>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
namespace boost { namespace parallel {
|
||||
|
||||
template<typename IndexMap, typename GlobalMap>
|
||||
class global_index_map
|
||||
{
|
||||
public:
|
||||
typedef typename property_traits<IndexMap>::key_type key_type;
|
||||
typedef typename property_traits<IndexMap>::value_type value_type;
|
||||
typedef value_type reference;
|
||||
typedef readable_property_map_tag category;
|
||||
|
||||
template<typename ProcessGroup>
|
||||
global_index_map(ProcessGroup pg, value_type num_local_indices,
|
||||
IndexMap index_map, GlobalMap global)
|
||||
: index_map(index_map), global(global)
|
||||
{
|
||||
typedef typename ProcessGroup::process_id_type process_id_type;
|
||||
starting_index.reset(new std::vector<value_type>(num_processes(pg) + 1));
|
||||
send(pg, 0, 0, num_local_indices);
|
||||
synchronize(pg);
|
||||
|
||||
// Populate starting_index in all processes
|
||||
if (process_id(pg) == 0) {
|
||||
(*starting_index)[0] = 0;
|
||||
for (process_id_type src = 0; src < num_processes(pg); ++src) {
|
||||
value_type n;
|
||||
receive(pg, src, 0, n);
|
||||
(*starting_index)[src + 1] = (*starting_index)[src] + n;
|
||||
}
|
||||
for (process_id_type dest = 1; dest < num_processes(pg); ++dest)
|
||||
send(pg, dest, 1, &starting_index->front(), num_processes(pg));
|
||||
synchronize(pg);
|
||||
} else {
|
||||
synchronize(pg);
|
||||
receive(pg, 0, 1, &starting_index->front(), num_processes(pg));
|
||||
}
|
||||
}
|
||||
|
||||
friend inline value_type
|
||||
get(const global_index_map& gim, const key_type& x)
|
||||
{
|
||||
using boost::get;
|
||||
return (*gim.starting_index)[get(gim.global, x).first]
|
||||
+ get(gim.index_map, x);
|
||||
}
|
||||
|
||||
private:
|
||||
shared_ptr<std::vector<value_type> > starting_index;
|
||||
IndexMap index_map;
|
||||
GlobalMap global;
|
||||
};
|
||||
|
||||
} } // end namespace boost::parallel
|
||||
|
||||
#endif // BOOST_PARALLEL_GLOBAL_INDEX_MAP_HPP
|
||||
432
test/external/boost/property_map/parallel/impl/distributed_property_map.ipp
vendored
Normal file
432
test/external/boost/property_map/parallel/impl/distributed_property_map.ipp
vendored
Normal file
@@ -0,0 +1,432 @@
|
||||
// Copyright (C) 2004-2006 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Authors: Douglas Gregor
|
||||
// Nick Edmonds
|
||||
// Andrew Lumsdaine
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/property_map/parallel/distributed_property_map.hpp>
|
||||
#include <boost/graph/parallel/detail/untracked_pair.hpp>
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/graph/parallel/simple_trigger.hpp>
|
||||
|
||||
#ifndef BOOST_GRAPH_USE_MPI
|
||||
#error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
|
||||
#endif
|
||||
|
||||
namespace boost { namespace parallel {
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
PBGL_DISTRIB_PMAP
|
||||
::distributed_property_map(const ProcessGroup& pg, const GlobalMap& global,
|
||||
const StorageMap& pm, const Reduce& reduce)
|
||||
: data(new data_t(pg, global, pm, reduce, Reduce::non_default_resolver))
|
||||
{
|
||||
typedef handle_message<Reduce> Handler;
|
||||
|
||||
data->ghost_cells.reset(new ghost_cells_type());
|
||||
data->reset = &data_t::template do_reset<Reduce>;
|
||||
data->process_group.replace_handler(Handler(data, reduce));
|
||||
data->process_group.template get_receiver<Handler>()
|
||||
->setup_triggers(data->process_group);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
PBGL_DISTRIB_PMAP::~distributed_property_map() { }
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::set_reduce(const Reduce& reduce)
|
||||
{
|
||||
typedef handle_message<Reduce> Handler;
|
||||
data->process_group.replace_handler(Handler(data, reduce));
|
||||
Handler* handler = data->process_group.template get_receiver<Handler>();
|
||||
BOOST_ASSERT(handler);
|
||||
handler->setup_triggers(data->process_group);
|
||||
data->get_default_value = reduce;
|
||||
data->has_default_resolver = Reduce::non_default_resolver;
|
||||
int model = data->model;
|
||||
data->reset = &data_t::template do_reset<Reduce>;
|
||||
set_consistency_model(model);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::prune_ghost_cells() const
|
||||
{
|
||||
if (data->max_ghost_cells == 0)
|
||||
return;
|
||||
|
||||
while (data->ghost_cells->size() > data->max_ghost_cells) {
|
||||
// Evict the last ghost cell
|
||||
|
||||
if (data->model & cm_flush) {
|
||||
// We need to flush values when we evict them.
|
||||
boost::parallel::detail::untracked_pair<key_type, value_type> const& victim
|
||||
= data->ghost_cells->back();
|
||||
send(data->process_group, get(data->global, victim.first).first,
|
||||
property_map_put, victim);
|
||||
}
|
||||
|
||||
// Actually remove the ghost cell
|
||||
data->ghost_cells->pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
typename PBGL_DISTRIB_PMAP::value_type&
|
||||
PBGL_DISTRIB_PMAP::cell(const key_type& key, bool request_if_missing) const
|
||||
{
|
||||
// Index by key
|
||||
ghost_cells_key_index_type const& key_index
|
||||
= data->ghost_cells->template get<1>();
|
||||
|
||||
// Search for the ghost cell by key, and project back to the sequence
|
||||
iterator ghost_cell
|
||||
= data->ghost_cells->template project<0>(key_index.find(key));
|
||||
if (ghost_cell == data->ghost_cells->end()) {
|
||||
value_type value;
|
||||
if (data->has_default_resolver)
|
||||
// Since we have a default resolver, use it to create a default
|
||||
// value for this ghost cell.
|
||||
value = data->get_default_value(key);
|
||||
else if (request_if_missing)
|
||||
// Request the actual value of this key from its owner
|
||||
send_oob_with_reply(data->process_group, get(data->global, key).first,
|
||||
property_map_get, key, value);
|
||||
else
|
||||
value = value_type();
|
||||
|
||||
// Create a ghost cell containing the new value
|
||||
ghost_cell
|
||||
= data->ghost_cells->push_front(std::make_pair(key, value)).first;
|
||||
|
||||
// If we need to, prune the ghost cells
|
||||
if (data->max_ghost_cells > 0)
|
||||
prune_ghost_cells();
|
||||
} else if (data->max_ghost_cells > 0)
|
||||
// Put this cell at the beginning of the MRU list
|
||||
data->ghost_cells->relocate(data->ghost_cells->begin(), ghost_cell);
|
||||
|
||||
return const_cast<value_type&>(ghost_cell->second);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP
|
||||
::handle_message<Reduce>::operator()(process_id_type source, int tag)
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::handle_message<Reduce>::
|
||||
handle_put(int /*source*/, int /*tag*/,
|
||||
const boost::parallel::detail::untracked_pair<key_type, value_type>& req, trigger_receive_context)
|
||||
{
|
||||
using boost::get;
|
||||
|
||||
shared_ptr<data_t> data(data_ptr);
|
||||
|
||||
owner_local_pair p = get(data->global, req.first);
|
||||
BOOST_ASSERT(p.first == process_id(data->process_group));
|
||||
|
||||
detail::maybe_put(data->storage, p.second,
|
||||
reduce(req.first,
|
||||
get(data->storage, p.second),
|
||||
req.second));
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
typename PBGL_DISTRIB_PMAP::value_type
|
||||
PBGL_DISTRIB_PMAP::handle_message<Reduce>::
|
||||
handle_get(int source, int /*tag*/, const key_type& key,
|
||||
trigger_receive_context)
|
||||
{
|
||||
using boost::get;
|
||||
|
||||
shared_ptr<data_t> data(data_ptr);
|
||||
BOOST_ASSERT(data);
|
||||
|
||||
owner_local_pair p = get(data->global, key);
|
||||
return get(data->storage, p.second);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::handle_message<Reduce>::
|
||||
handle_multiget(int source, int tag, const std::vector<key_type>& keys,
|
||||
trigger_receive_context)
|
||||
{
|
||||
shared_ptr<data_t> data(data_ptr);
|
||||
BOOST_ASSERT(data);
|
||||
|
||||
typedef boost::parallel::detail::untracked_pair<key_type, value_type> key_value;
|
||||
std::vector<key_value> results;
|
||||
std::size_t n = keys.size();
|
||||
results.reserve(n);
|
||||
|
||||
using boost::get;
|
||||
|
||||
for (std::size_t i = 0; i < n; ++i) {
|
||||
local_key_type local_key = get(data->global, keys[i]).second;
|
||||
results.push_back(key_value(keys[i], get(data->storage, local_key)));
|
||||
}
|
||||
send(data->process_group, source, property_map_multiget_reply, results);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::handle_message<Reduce>::
|
||||
handle_multiget_reply
|
||||
(int source, int tag,
|
||||
const std::vector<boost::parallel::detail::untracked_pair<key_type, value_type> >& msg,
|
||||
trigger_receive_context)
|
||||
{
|
||||
shared_ptr<data_t> data(data_ptr);
|
||||
BOOST_ASSERT(data);
|
||||
|
||||
// Index by key
|
||||
ghost_cells_key_index_type const& key_index
|
||||
= data->ghost_cells->template get<1>();
|
||||
|
||||
std::size_t n = msg.size();
|
||||
for (std::size_t i = 0; i < n; ++i) {
|
||||
// Search for the ghost cell by key, and project back to the sequence
|
||||
iterator position
|
||||
= data->ghost_cells->template project<0>(key_index.find(msg[i].first));
|
||||
|
||||
if (position != data->ghost_cells->end())
|
||||
const_cast<value_type&>(position->second) = msg[i].second;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::handle_message<Reduce>::
|
||||
handle_multiput
|
||||
(int source, int tag,
|
||||
const std::vector<unsafe_pair<local_key_type, value_type> >& values,
|
||||
trigger_receive_context)
|
||||
{
|
||||
using boost::get;
|
||||
|
||||
shared_ptr<data_t> data(data_ptr);
|
||||
BOOST_ASSERT(data);
|
||||
|
||||
std::size_t n = values.size();
|
||||
for (std::size_t i = 0; i < n; ++i) {
|
||||
local_key_type local_key = values[i].first;
|
||||
value_type local_value = get(data->storage, local_key);
|
||||
detail::maybe_put(data->storage, values[i].first,
|
||||
reduce(values[i].first,
|
||||
local_value,
|
||||
values[i].second));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Reduce>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::handle_message<Reduce>::
|
||||
setup_triggers(process_group_type& pg)
|
||||
{
|
||||
using boost::graph::parallel::simple_trigger;
|
||||
|
||||
simple_trigger(pg, property_map_put, this, &handle_message::handle_put);
|
||||
simple_trigger(pg, property_map_get, this, &handle_message::handle_get);
|
||||
simple_trigger(pg, property_map_multiget, this,
|
||||
&handle_message::handle_multiget);
|
||||
simple_trigger(pg, property_map_multiget_reply, this,
|
||||
&handle_message::handle_multiget_reply);
|
||||
simple_trigger(pg, property_map_multiput, this,
|
||||
&handle_message::handle_multiput);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP
|
||||
::on_synchronize::operator()()
|
||||
{
|
||||
int stage=0; // we only get called at the start now
|
||||
shared_ptr<data_t> data(data_ptr);
|
||||
BOOST_ASSERT(data);
|
||||
|
||||
// Determine in which stage backward consistency messages should be sent.
|
||||
int backward_stage = -1;
|
||||
if (data->model & cm_backward) {
|
||||
if (data->model & cm_flush) backward_stage = 1;
|
||||
else backward_stage = 0;
|
||||
}
|
||||
|
||||
// Flush results in first stage
|
||||
if (stage == 0 && data->model & cm_flush)
|
||||
data->flush();
|
||||
|
||||
// Backward consistency
|
||||
if (stage == backward_stage && !(data->model & (cm_clear | cm_reset)))
|
||||
data->refresh_ghost_cells();
|
||||
|
||||
// Optionally clear results
|
||||
if (data->model & cm_clear)
|
||||
data->clear();
|
||||
|
||||
// Optionally reset results
|
||||
if (data->model & cm_reset) {
|
||||
if (data->reset) ((*data).*data->reset)();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::set_consistency_model(int model)
|
||||
{
|
||||
data->model = model;
|
||||
|
||||
int stages = 1;
|
||||
bool need_on_synchronize = (model != cm_forward);
|
||||
|
||||
// Backward consistency is a two-stage process.
|
||||
if (model & cm_backward) {
|
||||
if (model & cm_flush) stages = 3;
|
||||
else stages = 2;
|
||||
|
||||
// For backward consistency to work, we absolutely cannot throw
|
||||
// away any ghost cells.
|
||||
data->max_ghost_cells = 0;
|
||||
}
|
||||
|
||||
// attach the on_synchronize handler.
|
||||
if (need_on_synchronize)
|
||||
data->process_group.replace_on_synchronize_handler(on_synchronize(data));
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void
|
||||
PBGL_DISTRIB_PMAP::set_max_ghost_cells(std::size_t max_ghost_cells)
|
||||
{
|
||||
if ((data->model & cm_backward) && max_ghost_cells > 0)
|
||||
boost::throw_exception(std::runtime_error("distributed_property_map::set_max_ghost_cells: "
|
||||
"cannot limit ghost-cell usage with a backward "
|
||||
"consistency model"));
|
||||
|
||||
if (max_ghost_cells == 1)
|
||||
// It is not safe to have only 1 ghost cell; the cell() method
|
||||
// will fail.
|
||||
max_ghost_cells = 2;
|
||||
|
||||
data->max_ghost_cells = max_ghost_cells;
|
||||
prune_ghost_cells();
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::clear()
|
||||
{
|
||||
data->clear();
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::data_t::clear()
|
||||
{
|
||||
ghost_cells->clear();
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::reset()
|
||||
{
|
||||
if (data->reset) ((*data).*data->reset)();
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::flush()
|
||||
{
|
||||
data->flush();
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::data_t::refresh_ghost_cells()
|
||||
{
|
||||
using boost::get;
|
||||
|
||||
std::vector<std::vector<key_type> > keys;
|
||||
keys.resize(num_processes(process_group));
|
||||
|
||||
// Collect the set of keys for which we will request values
|
||||
for (iterator i = ghost_cells->begin(); i != ghost_cells->end(); ++i)
|
||||
keys[get(global, i->first).first].push_back(i->first);
|
||||
|
||||
// Send multiget requests to each of the other processors
|
||||
typedef typename ProcessGroup::process_size_type process_size_type;
|
||||
process_size_type n = num_processes(process_group);
|
||||
process_id_type id = process_id(process_group);
|
||||
for (process_size_type p = (id + 1) % n ; p != id ; p = (p + 1) % n) {
|
||||
if (!keys[p].empty())
|
||||
send(process_group, p, property_map_multiget, keys[p]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::data_t::flush()
|
||||
{
|
||||
using boost::get;
|
||||
|
||||
int n = num_processes(process_group);
|
||||
std::vector<std::vector<unsafe_pair<local_key_type, value_type> > > values;
|
||||
values.resize(n);
|
||||
|
||||
// Collect all of the flushed values
|
||||
for (iterator i = ghost_cells->begin(); i != ghost_cells->end(); ++i) {
|
||||
std::pair<int, local_key_type> g = get(global, i->first);
|
||||
values[g.first].push_back(std::make_pair(g.second, i->second));
|
||||
}
|
||||
|
||||
// Transmit flushed values
|
||||
for (int p = 0; p < n; ++p) {
|
||||
if (!values[p].empty())
|
||||
send(process_group, p, property_map_multiput, values[p]);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
void PBGL_DISTRIB_PMAP::do_synchronize()
|
||||
{
|
||||
if (data->model & cm_backward) {
|
||||
synchronize(data->process_group);
|
||||
return;
|
||||
}
|
||||
|
||||
// Request refreshes of the values of our ghost cells
|
||||
data->refresh_ghost_cells();
|
||||
|
||||
// Allows all of the multigets to get to their destinations
|
||||
synchronize(data->process_group);
|
||||
|
||||
// Allows all of the multiget responses to get to their destinations
|
||||
synchronize(data->process_group);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
template<typename Resolver>
|
||||
void PBGL_DISTRIB_PMAP::data_t::do_reset()
|
||||
{
|
||||
Resolver* resolver = get_default_value.template target<Resolver>();
|
||||
BOOST_ASSERT(resolver);
|
||||
|
||||
for (iterator i = ghost_cells->begin(); i != ghost_cells->end(); ++i)
|
||||
const_cast<value_type&>(i->second) = (*resolver)(i->first);
|
||||
}
|
||||
|
||||
} } // end namespace boost::parallel
|
||||
91
test/external/boost/property_map/parallel/local_property_map.hpp
vendored
Normal file
91
test/external/boost/property_map/parallel/local_property_map.hpp
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (C) 2004-2006 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Authors: Douglas Gregor
|
||||
// Andrew Lumsdaine
|
||||
|
||||
// The placement of this #include probably looks very odd relative to
|
||||
// the #ifndef/#define pair below. However, this placement is
|
||||
// extremely important to allow the various property map headers to be
|
||||
// included in any order.
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
|
||||
#ifndef BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
|
||||
#define BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
|
||||
|
||||
#ifndef BOOST_GRAPH_USE_MPI
|
||||
#error "Parallel BGL files should not be included unless <boost/graph/use_mpi.hpp> has been included"
|
||||
#endif
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost {
|
||||
/** Property map that accesses an underlying, local property map
|
||||
* using a subset of the global keys.
|
||||
*/
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
class local_property_map
|
||||
{
|
||||
typedef typename property_traits<GlobalMap>::value_type owner_local_pair;
|
||||
|
||||
public:
|
||||
typedef ProcessGroup process_group_type;
|
||||
typedef typename property_traits<StorageMap>::value_type value_type;
|
||||
typedef typename property_traits<GlobalMap>::key_type key_type;
|
||||
typedef typename property_traits<StorageMap>::reference reference;
|
||||
typedef typename property_traits<StorageMap>::category category;
|
||||
|
||||
local_property_map() { }
|
||||
|
||||
local_property_map(const ProcessGroup& process_group,
|
||||
const GlobalMap& global, const StorageMap& storage)
|
||||
: process_group_(process_group), global_(global), storage(storage) { }
|
||||
|
||||
reference operator[](const key_type& key)
|
||||
{
|
||||
owner_local_pair p = get(global_, key);
|
||||
BOOST_ASSERT(p.first == process_id(process_group_));
|
||||
return storage[p.second];
|
||||
}
|
||||
|
||||
GlobalMap& global() const { return global_; }
|
||||
StorageMap& base() const { return storage; }
|
||||
|
||||
ProcessGroup& process_group() { return process_group_; }
|
||||
const ProcessGroup& process_group() const { return process_group_; }
|
||||
|
||||
private:
|
||||
ProcessGroup process_group_;
|
||||
mutable GlobalMap global_;
|
||||
mutable StorageMap storage;
|
||||
};
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
inline
|
||||
typename local_property_map<ProcessGroup, GlobalMap, StorageMap>::reference
|
||||
get(const local_property_map<ProcessGroup, GlobalMap, StorageMap>& pm,
|
||||
typename local_property_map<ProcessGroup, GlobalMap, StorageMap>::key_type
|
||||
const & key)
|
||||
|
||||
{
|
||||
typename property_traits<GlobalMap>::value_type p = get(pm.global(), key);
|
||||
return get(pm.base(), p.second);
|
||||
}
|
||||
|
||||
template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
|
||||
inline void
|
||||
put(const local_property_map<ProcessGroup, GlobalMap, StorageMap>& pm,
|
||||
typename local_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
::key_type const & key,
|
||||
typename local_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
::value_type const& v)
|
||||
{
|
||||
typename property_traits<GlobalMap>::value_type p = get(pm.global(), key);
|
||||
BOOST_ASSERT(p.first == process_id(pm.process_group()));
|
||||
put(pm.base(), p.second, v);
|
||||
}
|
||||
} // end namespace boost
|
||||
#endif // BOOST_PARALLEL_LOCAL_PROPERTY_MAP_HPP
|
||||
847
test/external/boost/property_map/property_map.hpp
vendored
Normal file
847
test/external/boost/property_map/property_map.hpp
vendored
Normal file
@@ -0,0 +1,847 @@
|
||||
// (C) Copyright Jeremy Siek 1999-2001.
|
||||
// Copyright (C) 2006 Trustees of Indiana University
|
||||
// Authors: Douglas Gregor and Jeremy Siek
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/property_map for documentation.
|
||||
|
||||
#ifndef BOOST_PROPERTY_MAP_HPP
|
||||
#define BOOST_PROPERTY_MAP_HPP
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/pending/cstddef.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/concept_check.hpp>
|
||||
#include <boost/concept_archetype.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
//=========================================================================
|
||||
// property_traits class
|
||||
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(key_type)
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type)
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(reference)
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(category)
|
||||
|
||||
template<class PA>
|
||||
struct is_property_map :
|
||||
boost::mpl::and_<
|
||||
has_key_type<PA>,
|
||||
has_value_type<PA>,
|
||||
has_reference<PA>,
|
||||
has_category<PA>
|
||||
>
|
||||
{};
|
||||
|
||||
template <typename PA>
|
||||
struct default_property_traits {
|
||||
typedef typename PA::key_type key_type;
|
||||
typedef typename PA::value_type value_type;
|
||||
typedef typename PA::reference reference;
|
||||
typedef typename PA::category category;
|
||||
};
|
||||
|
||||
struct null_property_traits {};
|
||||
|
||||
template <typename PA>
|
||||
struct property_traits :
|
||||
boost::mpl::if_<is_property_map<PA>,
|
||||
default_property_traits<PA>,
|
||||
null_property_traits>::type
|
||||
{};
|
||||
|
||||
#if 0
|
||||
template <typename PA>
|
||||
struct property_traits {
|
||||
typedef typename PA::key_type key_type;
|
||||
typedef typename PA::value_type value_type;
|
||||
typedef typename PA::reference reference;
|
||||
typedef typename PA::category category;
|
||||
};
|
||||
#endif
|
||||
|
||||
//=========================================================================
|
||||
// property_traits category tags
|
||||
|
||||
namespace detail {
|
||||
enum ePropertyMapID { READABLE_PA, WRITABLE_PA,
|
||||
READ_WRITE_PA, LVALUE_PA, OP_BRACKET_PA,
|
||||
RAND_ACCESS_ITER_PA, LAST_PA };
|
||||
}
|
||||
struct readable_property_map_tag { enum { id = detail::READABLE_PA }; };
|
||||
struct writable_property_map_tag { enum { id = detail::WRITABLE_PA }; };
|
||||
struct read_write_property_map_tag :
|
||||
public readable_property_map_tag,
|
||||
public writable_property_map_tag
|
||||
{ enum { id = detail::READ_WRITE_PA }; };
|
||||
|
||||
struct lvalue_property_map_tag : public read_write_property_map_tag
|
||||
{ enum { id = detail::LVALUE_PA }; };
|
||||
|
||||
//=========================================================================
|
||||
// property_traits specialization for pointers
|
||||
|
||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
// The user will just have to create their own specializations for
|
||||
// other pointers types if the compiler does not have partial
|
||||
// specializations. Sorry!
|
||||
#define BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(TYPE) \
|
||||
template <> \
|
||||
struct property_traits<TYPE*> { \
|
||||
typedef TYPE value_type; \
|
||||
typedef value_type& reference; \
|
||||
typedef std::ptrdiff_t key_type; \
|
||||
typedef lvalue_property_map_tag category; \
|
||||
}; \
|
||||
template <> \
|
||||
struct property_traits<const TYPE*> { \
|
||||
typedef TYPE value_type; \
|
||||
typedef const value_type& reference; \
|
||||
typedef std::ptrdiff_t key_type; \
|
||||
typedef lvalue_property_map_tag category; \
|
||||
}
|
||||
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned long);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(int);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned int);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(short);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned short);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(char);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(unsigned char);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(signed char);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(bool);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(float);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(double);
|
||||
BOOST_SPECIALIZE_PROPERTY_TRAITS_PTR(long double);
|
||||
|
||||
// This may need to be turned off for some older compilers that don't have
|
||||
// wchar_t intrinsically.
|
||||
# ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
template <>
|
||||
struct property_traits<wchar_t*> {
|
||||
typedef wchar_t value_type;
|
||||
typedef value_type& reference;
|
||||
typedef std::ptrdiff_t key_type;
|
||||
typedef lvalue_property_map_tag category;
|
||||
};
|
||||
template <>
|
||||
struct property_traits<const wchar_t*> {
|
||||
typedef wchar_t value_type;
|
||||
typedef const value_type& reference;
|
||||
typedef std::ptrdiff_t key_type;
|
||||
typedef lvalue_property_map_tag category;
|
||||
};
|
||||
# endif
|
||||
|
||||
#else
|
||||
template <class T>
|
||||
struct property_traits<T*> {
|
||||
typedef T value_type;
|
||||
typedef value_type& reference;
|
||||
typedef std::ptrdiff_t key_type;
|
||||
typedef lvalue_property_map_tag category;
|
||||
};
|
||||
template <class T>
|
||||
struct property_traits<const T*> {
|
||||
typedef T value_type;
|
||||
typedef const value_type& reference;
|
||||
typedef std::ptrdiff_t key_type;
|
||||
typedef lvalue_property_map_tag category;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
||||
// MSVC doesn't have Koenig lookup, so the user has to
|
||||
// do boost::get() anyways, and the using clause
|
||||
// doesn't really work for MSVC.
|
||||
} // namespace boost
|
||||
#endif
|
||||
|
||||
// These need to go in global namespace because Koenig
|
||||
// lookup does not apply to T*.
|
||||
|
||||
// V must be convertible to T
|
||||
template <class T, class V>
|
||||
inline void put(T* pa, std::ptrdiff_t k, const V& val) { pa[k] = val; }
|
||||
|
||||
template <class T>
|
||||
inline const T& get(const T* pa, std::ptrdiff_t k) { return pa[k]; }
|
||||
|
||||
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
||||
namespace boost {
|
||||
using ::put;
|
||||
using ::get;
|
||||
#endif
|
||||
|
||||
//=========================================================================
|
||||
// concept checks for property maps
|
||||
|
||||
template <class PMap, class Key>
|
||||
struct ReadablePropertyMapConcept
|
||||
{
|
||||
typedef typename property_traits<PMap>::key_type key_type;
|
||||
typedef typename property_traits<PMap>::reference reference;
|
||||
typedef typename property_traits<PMap>::category Category;
|
||||
typedef boost::readable_property_map_tag ReadableTag;
|
||||
void constraints() {
|
||||
function_requires< ConvertibleConcept<Category, ReadableTag> >();
|
||||
|
||||
val = get(pmap, k);
|
||||
}
|
||||
PMap pmap;
|
||||
Key k;
|
||||
typename property_traits<PMap>::value_type val;
|
||||
};
|
||||
template <typename KeyArchetype, typename ValueArchetype>
|
||||
struct readable_property_map_archetype {
|
||||
typedef KeyArchetype key_type;
|
||||
typedef ValueArchetype value_type;
|
||||
typedef convertible_to_archetype<ValueArchetype> reference;
|
||||
typedef readable_property_map_tag category;
|
||||
};
|
||||
template <typename K, typename V>
|
||||
const typename readable_property_map_archetype<K,V>::reference&
|
||||
get(const readable_property_map_archetype<K,V>&,
|
||||
const typename readable_property_map_archetype<K,V>::key_type&)
|
||||
{
|
||||
typedef typename readable_property_map_archetype<K,V>::reference R;
|
||||
return static_object<R>::get();
|
||||
}
|
||||
|
||||
|
||||
template <class PMap, class Key>
|
||||
struct WritablePropertyMapConcept
|
||||
{
|
||||
typedef typename property_traits<PMap>::key_type key_type;
|
||||
typedef typename property_traits<PMap>::category Category;
|
||||
typedef boost::writable_property_map_tag WritableTag;
|
||||
void constraints() {
|
||||
function_requires< ConvertibleConcept<Category, WritableTag> >();
|
||||
put(pmap, k, val);
|
||||
}
|
||||
PMap pmap;
|
||||
Key k;
|
||||
typename property_traits<PMap>::value_type val;
|
||||
};
|
||||
template <typename KeyArchetype, typename ValueArchetype>
|
||||
struct writable_property_map_archetype {
|
||||
typedef KeyArchetype key_type;
|
||||
typedef ValueArchetype value_type;
|
||||
typedef void reference;
|
||||
typedef writable_property_map_tag category;
|
||||
};
|
||||
template <typename K, typename V>
|
||||
void put(const writable_property_map_archetype<K,V>&,
|
||||
const typename writable_property_map_archetype<K,V>::key_type&,
|
||||
const typename writable_property_map_archetype<K,V>::value_type&) { }
|
||||
|
||||
|
||||
template <class PMap, class Key>
|
||||
struct ReadWritePropertyMapConcept
|
||||
{
|
||||
typedef typename property_traits<PMap>::category Category;
|
||||
typedef boost::read_write_property_map_tag ReadWriteTag;
|
||||
void constraints() {
|
||||
function_requires< ReadablePropertyMapConcept<PMap, Key> >();
|
||||
function_requires< WritablePropertyMapConcept<PMap, Key> >();
|
||||
function_requires< ConvertibleConcept<Category, ReadWriteTag> >();
|
||||
}
|
||||
};
|
||||
template <typename KeyArchetype, typename ValueArchetype>
|
||||
struct read_write_property_map_archetype
|
||||
: public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
|
||||
public writable_property_map_archetype<KeyArchetype, ValueArchetype>
|
||||
{
|
||||
typedef KeyArchetype key_type;
|
||||
typedef ValueArchetype value_type;
|
||||
typedef convertible_to_archetype<ValueArchetype> reference;
|
||||
typedef read_write_property_map_tag category;
|
||||
};
|
||||
|
||||
|
||||
template <class PMap, class Key>
|
||||
struct LvaluePropertyMapConcept
|
||||
{
|
||||
typedef typename property_traits<PMap>::category Category;
|
||||
typedef boost::lvalue_property_map_tag LvalueTag;
|
||||
typedef typename property_traits<PMap>::reference reference;
|
||||
|
||||
void constraints() {
|
||||
function_requires< ReadablePropertyMapConcept<PMap, Key> >();
|
||||
function_requires< ConvertibleConcept<Category, LvalueTag> >();
|
||||
|
||||
typedef typename property_traits<PMap>::value_type value_type;
|
||||
BOOST_MPL_ASSERT((boost::mpl::or_<
|
||||
boost::is_same<const value_type&, reference>,
|
||||
boost::is_same<value_type&, reference> >));
|
||||
|
||||
reference ref = pmap[k];
|
||||
ignore_unused_variable_warning(ref);
|
||||
}
|
||||
PMap pmap;
|
||||
Key k;
|
||||
};
|
||||
template <typename KeyArchetype, typename ValueArchetype>
|
||||
struct lvalue_property_map_archetype
|
||||
: public readable_property_map_archetype<KeyArchetype, ValueArchetype>
|
||||
{
|
||||
typedef KeyArchetype key_type;
|
||||
typedef ValueArchetype value_type;
|
||||
typedef const ValueArchetype& reference;
|
||||
typedef lvalue_property_map_tag category;
|
||||
const value_type& operator[](const key_type&) const {
|
||||
return static_object<value_type>::get();
|
||||
}
|
||||
};
|
||||
|
||||
template <class PMap, class Key>
|
||||
struct Mutable_LvaluePropertyMapConcept
|
||||
{
|
||||
typedef typename property_traits<PMap>::category Category;
|
||||
typedef boost::lvalue_property_map_tag LvalueTag;
|
||||
typedef typename property_traits<PMap>::reference reference;
|
||||
void constraints() {
|
||||
boost::function_requires< ReadWritePropertyMapConcept<PMap, Key> >();
|
||||
boost::function_requires<ConvertibleConcept<Category, LvalueTag> >();
|
||||
|
||||
typedef typename property_traits<PMap>::value_type value_type;
|
||||
BOOST_MPL_ASSERT((boost::is_same<value_type&, reference>));
|
||||
|
||||
reference ref = pmap[k];
|
||||
ignore_unused_variable_warning(ref);
|
||||
}
|
||||
PMap pmap;
|
||||
Key k;
|
||||
};
|
||||
template <typename KeyArchetype, typename ValueArchetype>
|
||||
struct mutable_lvalue_property_map_archetype
|
||||
: public readable_property_map_archetype<KeyArchetype, ValueArchetype>,
|
||||
public writable_property_map_archetype<KeyArchetype, ValueArchetype>
|
||||
{
|
||||
typedef KeyArchetype key_type;
|
||||
typedef ValueArchetype value_type;
|
||||
typedef ValueArchetype& reference;
|
||||
typedef lvalue_property_map_tag category;
|
||||
value_type& operator[](const key_type&) const {
|
||||
return static_object<value_type>::get();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct typed_identity_property_map;
|
||||
|
||||
// A helper class for constructing a property map
|
||||
// from a class that implements operator[]
|
||||
|
||||
template <class Reference, class LvaluePropertyMap>
|
||||
struct put_get_helper { };
|
||||
|
||||
template <class PropertyMap, class Reference, class K>
|
||||
inline Reference
|
||||
get(const put_get_helper<Reference, PropertyMap>& pa, const K& k)
|
||||
{
|
||||
Reference v = static_cast<const PropertyMap&>(pa)[k];
|
||||
return v;
|
||||
}
|
||||
template <class PropertyMap, class Reference, class K, class V>
|
||||
inline void
|
||||
put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
|
||||
{
|
||||
static_cast<const PropertyMap&>(pa)[k] = v;
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// Adapter to turn a RandomAccessIterator into a property map
|
||||
|
||||
template <class RandomAccessIterator,
|
||||
class IndexMap
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
, class T, class R
|
||||
#else
|
||||
, class T = typename std::iterator_traits<RandomAccessIterator>::value_type
|
||||
, class R = typename std::iterator_traits<RandomAccessIterator>::reference
|
||||
#endif
|
||||
>
|
||||
class iterator_property_map
|
||||
: public boost::put_get_helper< R,
|
||||
iterator_property_map<RandomAccessIterator, IndexMap,
|
||||
T, R> >
|
||||
{
|
||||
public:
|
||||
typedef typename property_traits<IndexMap>::key_type key_type;
|
||||
typedef T value_type;
|
||||
typedef R reference;
|
||||
typedef boost::lvalue_property_map_tag category;
|
||||
|
||||
inline iterator_property_map(
|
||||
RandomAccessIterator cc = RandomAccessIterator(),
|
||||
const IndexMap& _id = IndexMap() )
|
||||
: iter(cc), index(_id) { }
|
||||
inline R operator[](key_type v) const { return *(iter + get(index, v)) ; }
|
||||
protected:
|
||||
RandomAccessIterator iter;
|
||||
IndexMap index;
|
||||
};
|
||||
|
||||
#if !defined BOOST_NO_STD_ITERATOR_TRAITS
|
||||
template <class RAIter, class ID>
|
||||
inline iterator_property_map<
|
||||
RAIter, ID,
|
||||
typename std::iterator_traits<RAIter>::value_type,
|
||||
typename std::iterator_traits<RAIter>::reference>
|
||||
make_iterator_property_map(RAIter iter, ID id) {
|
||||
function_requires< RandomAccessIteratorConcept<RAIter> >();
|
||||
typedef iterator_property_map<
|
||||
RAIter, ID,
|
||||
typename std::iterator_traits<RAIter>::value_type,
|
||||
typename std::iterator_traits<RAIter>::reference> PA;
|
||||
return PA(iter, id);
|
||||
}
|
||||
#endif
|
||||
template <class RAIter, class Value, class ID>
|
||||
inline iterator_property_map<RAIter, ID, Value, Value&>
|
||||
make_iterator_property_map(RAIter iter, ID id, Value) {
|
||||
function_requires< RandomAccessIteratorConcept<RAIter> >();
|
||||
typedef iterator_property_map<RAIter, ID, Value, Value&> PMap;
|
||||
return PMap(iter, id);
|
||||
}
|
||||
|
||||
template <class RandomAccessIterator,
|
||||
class IndexMap
|
||||
#ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
, class T, class R
|
||||
#else
|
||||
, class T = typename std::iterator_traits<RandomAccessIterator>::value_type
|
||||
, class R = typename std::iterator_traits<RandomAccessIterator>::reference
|
||||
#endif
|
||||
>
|
||||
class safe_iterator_property_map
|
||||
: public boost::put_get_helper< R,
|
||||
safe_iterator_property_map<RandomAccessIterator, IndexMap,
|
||||
T, R> >
|
||||
{
|
||||
public:
|
||||
typedef typename property_traits<IndexMap>::key_type key_type;
|
||||
typedef T value_type;
|
||||
typedef R reference;
|
||||
typedef boost::lvalue_property_map_tag category;
|
||||
|
||||
inline safe_iterator_property_map(
|
||||
RandomAccessIterator first,
|
||||
std::size_t n_ = 0,
|
||||
const IndexMap& _id = IndexMap() )
|
||||
: iter(first), n(n_), index(_id) { }
|
||||
inline safe_iterator_property_map() { }
|
||||
inline R operator[](key_type v) const {
|
||||
BOOST_ASSERT(get(index, v) < n);
|
||||
return *(iter + get(index, v)) ;
|
||||
}
|
||||
typename property_traits<IndexMap>::value_type size() const { return n; }
|
||||
protected:
|
||||
RandomAccessIterator iter;
|
||||
typename property_traits<IndexMap>::value_type n;
|
||||
IndexMap index;
|
||||
};
|
||||
|
||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class RAIter, class ID>
|
||||
inline safe_iterator_property_map<
|
||||
RAIter, ID,
|
||||
typename boost::detail::iterator_traits<RAIter>::value_type,
|
||||
typename boost::detail::iterator_traits<RAIter>::reference>
|
||||
make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id) {
|
||||
function_requires< RandomAccessIteratorConcept<RAIter> >();
|
||||
typedef safe_iterator_property_map<
|
||||
RAIter, ID,
|
||||
typename boost::detail::iterator_traits<RAIter>::value_type,
|
||||
typename boost::detail::iterator_traits<RAIter>::reference> PA;
|
||||
return PA(iter, n, id);
|
||||
}
|
||||
#endif
|
||||
template <class RAIter, class Value, class ID>
|
||||
inline safe_iterator_property_map<RAIter, ID, Value, Value&>
|
||||
make_safe_iterator_property_map(RAIter iter, std::size_t n, ID id, Value) {
|
||||
function_requires< RandomAccessIteratorConcept<RAIter> >();
|
||||
typedef safe_iterator_property_map<RAIter, ID, Value, Value&> PMap;
|
||||
return PMap(iter, n, id);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// An adaptor to turn a Unique Pair Associative Container like std::map or
|
||||
// std::hash_map into an Lvalue Property Map.
|
||||
|
||||
template <typename UniquePairAssociativeContainer>
|
||||
class associative_property_map
|
||||
: public boost::put_get_helper<
|
||||
typename UniquePairAssociativeContainer::value_type::second_type&,
|
||||
associative_property_map<UniquePairAssociativeContainer> >
|
||||
{
|
||||
typedef UniquePairAssociativeContainer C;
|
||||
public:
|
||||
typedef typename C::key_type key_type;
|
||||
typedef typename C::value_type::second_type value_type;
|
||||
typedef value_type& reference;
|
||||
typedef lvalue_property_map_tag category;
|
||||
associative_property_map() : m_c(0) { }
|
||||
associative_property_map(C& c) : m_c(&c) { }
|
||||
reference operator[](const key_type& k) const {
|
||||
return (*m_c)[k];
|
||||
}
|
||||
private:
|
||||
C* m_c;
|
||||
};
|
||||
|
||||
template <class UniquePairAssociativeContainer>
|
||||
associative_property_map<UniquePairAssociativeContainer>
|
||||
make_assoc_property_map(UniquePairAssociativeContainer& c)
|
||||
{
|
||||
return associative_property_map<UniquePairAssociativeContainer>(c);
|
||||
}
|
||||
|
||||
template <typename UniquePairAssociativeContainer>
|
||||
class const_associative_property_map
|
||||
: public boost::put_get_helper<
|
||||
const typename UniquePairAssociativeContainer::value_type::second_type&,
|
||||
const_associative_property_map<UniquePairAssociativeContainer> >
|
||||
{
|
||||
typedef UniquePairAssociativeContainer C;
|
||||
public:
|
||||
typedef typename C::key_type key_type;
|
||||
typedef typename C::value_type::second_type value_type;
|
||||
typedef const value_type& reference;
|
||||
typedef lvalue_property_map_tag category;
|
||||
const_associative_property_map() : m_c(0) { }
|
||||
const_associative_property_map(const C& c) : m_c(&c) { }
|
||||
reference operator[](const key_type& k) const {
|
||||
return m_c->find(k)->second;
|
||||
}
|
||||
private:
|
||||
C const* m_c;
|
||||
};
|
||||
|
||||
template <class UniquePairAssociativeContainer>
|
||||
const_associative_property_map<UniquePairAssociativeContainer>
|
||||
make_assoc_property_map(const UniquePairAssociativeContainer& c)
|
||||
{
|
||||
return const_associative_property_map<UniquePairAssociativeContainer>(c);
|
||||
}
|
||||
|
||||
//=========================================================================
|
||||
// A property map that always returns the same object by value.
|
||||
//
|
||||
template <typename ValueType>
|
||||
class static_property_map :
|
||||
public
|
||||
boost::put_get_helper<ValueType,static_property_map<ValueType> >
|
||||
{
|
||||
ValueType value;
|
||||
public:
|
||||
typedef void key_type;
|
||||
typedef ValueType value_type;
|
||||
typedef ValueType reference;
|
||||
typedef readable_property_map_tag category;
|
||||
static_property_map(ValueType v) : value(v) {}
|
||||
|
||||
template<typename T>
|
||||
inline reference operator[](T) const { return value; }
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
// A property map that always returns a reference to the same object.
|
||||
//
|
||||
template <typename KeyType, typename ValueType>
|
||||
class ref_property_map :
|
||||
public
|
||||
boost::put_get_helper<ValueType&,ref_property_map<KeyType,ValueType> >
|
||||
{
|
||||
ValueType* value;
|
||||
public:
|
||||
typedef KeyType key_type;
|
||||
typedef ValueType value_type;
|
||||
typedef ValueType& reference;
|
||||
typedef lvalue_property_map_tag category;
|
||||
ref_property_map(ValueType& v) : value(&v) {}
|
||||
ValueType& operator[](key_type const&) const { return *value; }
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
// A generalized identity property map
|
||||
template <typename T>
|
||||
struct typed_identity_property_map
|
||||
: public boost::put_get_helper<T, typed_identity_property_map<T> >
|
||||
{
|
||||
typedef T key_type;
|
||||
typedef T value_type;
|
||||
typedef T reference;
|
||||
typedef boost::readable_property_map_tag category;
|
||||
|
||||
inline value_type operator[](const key_type& v) const { return v; }
|
||||
};
|
||||
|
||||
//=========================================================================
|
||||
// A property map that applies the identity function to integers
|
||||
typedef typed_identity_property_map<std::size_t> identity_property_map;
|
||||
|
||||
//=========================================================================
|
||||
// A property map that does not do anything, for
|
||||
// when you have to supply a property map, but don't need it.
|
||||
namespace detail {
|
||||
struct dummy_pmap_reference {
|
||||
template <class T>
|
||||
dummy_pmap_reference& operator=(const T&) { return *this; }
|
||||
operator int() { return 0; }
|
||||
};
|
||||
}
|
||||
class dummy_property_map
|
||||
: public boost::put_get_helper<detail::dummy_pmap_reference,
|
||||
dummy_property_map >
|
||||
{
|
||||
public:
|
||||
typedef void key_type;
|
||||
typedef int value_type;
|
||||
typedef detail::dummy_pmap_reference reference;
|
||||
typedef boost::read_write_property_map_tag category;
|
||||
inline dummy_property_map() : c(0) { }
|
||||
inline dummy_property_map(value_type cc) : c(cc) { }
|
||||
inline dummy_property_map(const dummy_property_map& x)
|
||||
: c(x.c) { }
|
||||
template <class Vertex>
|
||||
inline reference operator[](Vertex) const { return reference(); }
|
||||
protected:
|
||||
value_type c;
|
||||
};
|
||||
|
||||
// Convert a Readable property map into a function object
|
||||
template <typename PropMap>
|
||||
class property_map_function {
|
||||
PropMap pm;
|
||||
typedef typename property_traits<PropMap>::key_type param_type;
|
||||
public:
|
||||
explicit property_map_function(const PropMap& pm): pm(pm) {}
|
||||
typedef typename property_traits<PropMap>::value_type result_type;
|
||||
result_type operator()(const param_type& k) const {return get(pm, k);}
|
||||
};
|
||||
|
||||
template <typename PropMap>
|
||||
property_map_function<PropMap>
|
||||
make_property_map_function(const PropMap& pm) {
|
||||
return property_map_function<PropMap>(pm);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_GRAPH_USE_MPI
|
||||
#include <boost/property_map/parallel/distributed_property_map.hpp>
|
||||
#include <boost/property_map/parallel/local_property_map.hpp>
|
||||
|
||||
namespace boost {
|
||||
/** Distributed iterator property map.
|
||||
*
|
||||
* This specialization of @ref iterator_property_map builds a
|
||||
* distributed iterator property map given the local index maps
|
||||
* generated by distributed graph types that automatically have index
|
||||
* properties.
|
||||
*
|
||||
* This specialization is useful when creating external distributed
|
||||
* property maps via the same syntax used to create external
|
||||
* sequential property maps.
|
||||
*/
|
||||
template<typename RandomAccessIterator, typename ProcessGroup,
|
||||
typename GlobalMap, typename StorageMap,
|
||||
typename ValueType, typename Reference>
|
||||
class iterator_property_map
|
||||
<RandomAccessIterator,
|
||||
local_property_map<ProcessGroup, GlobalMap, StorageMap>,
|
||||
ValueType, Reference>
|
||||
: public parallel::distributed_property_map
|
||||
<ProcessGroup,
|
||||
GlobalMap,
|
||||
iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> >
|
||||
{
|
||||
typedef iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> local_iterator_map;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
local_iterator_map> inherited;
|
||||
|
||||
typedef local_property_map<ProcessGroup, GlobalMap, StorageMap>
|
||||
index_map_type;
|
||||
typedef iterator_property_map self_type;
|
||||
|
||||
public:
|
||||
iterator_property_map() { }
|
||||
|
||||
iterator_property_map(RandomAccessIterator cc, const index_map_type& id)
|
||||
: inherited(id.process_group(), id.global(),
|
||||
local_iterator_map(cc, id.base())) { }
|
||||
};
|
||||
|
||||
/** Distributed iterator property map.
|
||||
*
|
||||
* This specialization of @ref iterator_property_map builds a
|
||||
* distributed iterator property map given a distributed index
|
||||
* map. Only the local portion of the distributed index property map
|
||||
* is utilized.
|
||||
*
|
||||
* This specialization is useful when creating external distributed
|
||||
* property maps via the same syntax used to create external
|
||||
* sequential property maps.
|
||||
*/
|
||||
template<typename RandomAccessIterator, typename ProcessGroup,
|
||||
typename GlobalMap, typename StorageMap,
|
||||
typename ValueType, typename Reference>
|
||||
class iterator_property_map<
|
||||
RandomAccessIterator,
|
||||
parallel::distributed_property_map<ProcessGroup,GlobalMap,StorageMap>,
|
||||
ValueType, Reference
|
||||
>
|
||||
: public parallel::distributed_property_map
|
||||
<ProcessGroup,
|
||||
GlobalMap,
|
||||
iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> >
|
||||
{
|
||||
typedef iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> local_iterator_map;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
local_iterator_map> inherited;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
StorageMap>
|
||||
index_map_type;
|
||||
|
||||
public:
|
||||
iterator_property_map() { }
|
||||
|
||||
iterator_property_map(RandomAccessIterator cc, const index_map_type& id)
|
||||
: inherited(id.process_group(), id.global(),
|
||||
local_iterator_map(cc, id.base())) { }
|
||||
};
|
||||
|
||||
namespace parallel {
|
||||
// Generate an iterator property map with a specific kind of ghost
|
||||
// cells
|
||||
template<typename RandomAccessIterator, typename ProcessGroup,
|
||||
typename GlobalMap, typename StorageMap>
|
||||
distributed_property_map<ProcessGroup,
|
||||
GlobalMap,
|
||||
iterator_property_map<RandomAccessIterator,
|
||||
StorageMap> >
|
||||
make_iterator_property_map(RandomAccessIterator cc,
|
||||
local_property_map<ProcessGroup, GlobalMap,
|
||||
StorageMap> index_map)
|
||||
{
|
||||
typedef distributed_property_map<
|
||||
ProcessGroup, GlobalMap,
|
||||
iterator_property_map<RandomAccessIterator, StorageMap> >
|
||||
result_type;
|
||||
return result_type(index_map.process_group(), index_map.global(),
|
||||
make_iterator_property_map(cc, index_map.base()));
|
||||
}
|
||||
|
||||
} // end namespace parallel
|
||||
|
||||
/** Distributed safe iterator property map.
|
||||
*
|
||||
* This specialization of @ref safe_iterator_property_map builds a
|
||||
* distributed iterator property map given the local index maps
|
||||
* generated by distributed graph types that automatically have index
|
||||
* properties.
|
||||
*
|
||||
* This specialization is useful when creating external distributed
|
||||
* property maps via the same syntax used to create external
|
||||
* sequential property maps.
|
||||
*/
|
||||
template<typename RandomAccessIterator, typename ProcessGroup,
|
||||
typename GlobalMap, typename StorageMap, typename ValueType,
|
||||
typename Reference>
|
||||
class safe_iterator_property_map
|
||||
<RandomAccessIterator,
|
||||
local_property_map<ProcessGroup, GlobalMap, StorageMap>,
|
||||
ValueType, Reference>
|
||||
: public parallel::distributed_property_map
|
||||
<ProcessGroup,
|
||||
GlobalMap,
|
||||
safe_iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> >
|
||||
{
|
||||
typedef safe_iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> local_iterator_map;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
local_iterator_map> inherited;
|
||||
|
||||
typedef local_property_map<ProcessGroup, GlobalMap, StorageMap> index_map_type;
|
||||
|
||||
public:
|
||||
safe_iterator_property_map() { }
|
||||
|
||||
safe_iterator_property_map(RandomAccessIterator cc, std::size_t n,
|
||||
const index_map_type& id)
|
||||
: inherited(id.process_group(), id.global(),
|
||||
local_iterator_map(cc, n, id.base())) { }
|
||||
};
|
||||
|
||||
/** Distributed safe iterator property map.
|
||||
*
|
||||
* This specialization of @ref safe_iterator_property_map builds a
|
||||
* distributed iterator property map given a distributed index
|
||||
* map. Only the local portion of the distributed index property map
|
||||
* is utilized.
|
||||
*
|
||||
* This specialization is useful when creating external distributed
|
||||
* property maps via the same syntax used to create external
|
||||
* sequential property maps.
|
||||
*/
|
||||
template<typename RandomAccessIterator, typename ProcessGroup,
|
||||
typename GlobalMap, typename StorageMap,
|
||||
typename ValueType, typename Reference>
|
||||
class safe_iterator_property_map<
|
||||
RandomAccessIterator,
|
||||
parallel::distributed_property_map<ProcessGroup,GlobalMap,StorageMap>,
|
||||
ValueType, Reference>
|
||||
: public parallel::distributed_property_map
|
||||
<ProcessGroup,
|
||||
GlobalMap,
|
||||
safe_iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> >
|
||||
{
|
||||
typedef safe_iterator_property_map<RandomAccessIterator, StorageMap,
|
||||
ValueType, Reference> local_iterator_map;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
local_iterator_map> inherited;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
StorageMap>
|
||||
index_map_type;
|
||||
|
||||
public:
|
||||
safe_iterator_property_map() { }
|
||||
|
||||
safe_iterator_property_map(RandomAccessIterator cc, std::size_t n,
|
||||
const index_map_type& id)
|
||||
: inherited(id.process_group(), id.global(),
|
||||
local_iterator_map(cc, n, id.base())) { }
|
||||
};
|
||||
|
||||
}
|
||||
#endif // BOOST_GRAPH_USE_MPI
|
||||
|
||||
#include <boost/property_map/vector_property_map.hpp>
|
||||
|
||||
#endif /* BOOST_PROPERTY_MAP_HPP */
|
||||
|
||||
113
test/external/boost/property_map/property_map_iterator.hpp
vendored
Normal file
113
test/external/boost/property_map/property_map_iterator.hpp
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
// (C) Copyright Jeremy Siek, 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/property_map for documentation.
|
||||
|
||||
#ifndef BOOST_PROPERTY_MAP_ITERATOR_HPP
|
||||
#define BOOST_PROPERTY_MAP_ITERATOR_HPP
|
||||
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
//======================================================================
|
||||
// property iterator, generalized from ideas by Francois Faure
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class Iterator, class LvaluePropertyMap>
|
||||
class lvalue_pmap_iter
|
||||
: public iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
|
||||
Iterator,
|
||||
typename property_traits<LvaluePropertyMap>::value_type,
|
||||
use_default,
|
||||
typename property_traits<LvaluePropertyMap>::reference>
|
||||
{
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
typedef iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
|
||||
Iterator,
|
||||
typename property_traits<LvaluePropertyMap>::value_type,
|
||||
use_default,
|
||||
typename property_traits<LvaluePropertyMap>::reference> super_t;
|
||||
|
||||
public:
|
||||
lvalue_pmap_iter() { }
|
||||
lvalue_pmap_iter(Iterator const& it,
|
||||
LvaluePropertyMap m)
|
||||
: super_t(it),
|
||||
m_map(m) {}
|
||||
|
||||
private:
|
||||
typename super_t::reference
|
||||
dereference() const
|
||||
{
|
||||
return m_map[*(this->base_reference())];
|
||||
}
|
||||
|
||||
LvaluePropertyMap m_map;
|
||||
};
|
||||
|
||||
template <class Iterator, class ReadablePropertyMap>
|
||||
class readable_pmap_iter :
|
||||
public iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
|
||||
Iterator,
|
||||
typename property_traits<ReadablePropertyMap>::value_type,
|
||||
use_default,
|
||||
typename property_traits<ReadablePropertyMap>::value_type>
|
||||
|
||||
|
||||
{
|
||||
friend class boost::iterator_core_access;
|
||||
|
||||
typedef iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
|
||||
Iterator,
|
||||
typename property_traits<ReadablePropertyMap>::value_type,
|
||||
use_default,
|
||||
typename property_traits<ReadablePropertyMap>::value_type> super_t;
|
||||
|
||||
public:
|
||||
readable_pmap_iter() { }
|
||||
readable_pmap_iter(Iterator const& it,
|
||||
ReadablePropertyMap m)
|
||||
: super_t(it),
|
||||
m_map(m) {}
|
||||
|
||||
private:
|
||||
typename super_t::reference
|
||||
dereference() const
|
||||
{
|
||||
return get(m_map, *(this->base_reference()));
|
||||
}
|
||||
|
||||
ReadablePropertyMap m_map;
|
||||
};
|
||||
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <class PropertyMap, class Iterator>
|
||||
struct property_map_iterator_generator :
|
||||
mpl::if_< is_same< typename property_traits<PropertyMap>::category, lvalue_property_map_tag>,
|
||||
detail::lvalue_pmap_iter<Iterator, PropertyMap>,
|
||||
detail::readable_pmap_iter<Iterator, PropertyMap> >
|
||||
{};
|
||||
|
||||
template <class PropertyMap, class Iterator>
|
||||
typename property_map_iterator_generator<PropertyMap, Iterator>::type
|
||||
make_property_map_iterator(PropertyMap pmap, Iterator iter)
|
||||
{
|
||||
typedef typename property_map_iterator_generator<PropertyMap,
|
||||
Iterator>::type Iter;
|
||||
return Iter(iter, pmap);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_PROPERTY_MAP_ITERATOR_HPP
|
||||
|
||||
52
test/external/boost/property_map/shared_array_property_map.hpp
vendored
Normal file
52
test/external/boost/property_map/shared_array_property_map.hpp
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright (C) 2009 Trustees of Indiana University
|
||||
// Authors: Jeremiah Willcock, Andrew Lumsdaine
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/property_map for documentation.
|
||||
|
||||
#ifndef BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
|
||||
#define BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
|
||||
|
||||
#include <boost/smart_ptr/shared_array.hpp>
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class T, class IndexMap>
|
||||
class shared_array_property_map
|
||||
: public boost::put_get_helper<T&, shared_array_property_map<T, IndexMap> >
|
||||
{
|
||||
public:
|
||||
typedef typename property_traits<IndexMap>::key_type key_type;
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef boost::lvalue_property_map_tag category;
|
||||
|
||||
inline shared_array_property_map(): data(), index() {}
|
||||
|
||||
explicit inline shared_array_property_map(
|
||||
size_t n,
|
||||
const IndexMap& _id = IndexMap())
|
||||
: data(new T[n]), index(_id) {}
|
||||
|
||||
inline T& operator[](key_type v) const {
|
||||
return data[get(index, v)];
|
||||
}
|
||||
|
||||
private:
|
||||
boost::shared_array<T> data;
|
||||
IndexMap index;
|
||||
};
|
||||
|
||||
template <class T, class IndexMap>
|
||||
shared_array_property_map<T, IndexMap>
|
||||
make_shared_array_property_map(size_t n, const T&, const IndexMap& index) {
|
||||
return shared_array_property_map<T, IndexMap>(n, index);
|
||||
}
|
||||
|
||||
} // end namespace boost
|
||||
|
||||
#endif // BOOST_SHARED_ARRAY_PROPERTY_MAP_HPP
|
||||
185
test/external/boost/property_map/vector_property_map.hpp
vendored
Normal file
185
test/external/boost/property_map/vector_property_map.hpp
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
// Copyright (C) Vladimir Prus 2003.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/libs/graph/vector_property_map.html for
|
||||
// documentation.
|
||||
//
|
||||
|
||||
#ifndef VECTOR_PROPERTY_MAP_HPP_VP_2003_03_04
|
||||
#define VECTOR_PROPERTY_MAP_HPP_VP_2003_03_04
|
||||
|
||||
#include <boost/property_map/property_map.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace boost {
|
||||
template<typename T, typename IndexMap = identity_property_map>
|
||||
class vector_property_map
|
||||
: public boost::put_get_helper<
|
||||
typename std::iterator_traits<
|
||||
typename std::vector<T>::iterator >::reference,
|
||||
vector_property_map<T, IndexMap> >
|
||||
{
|
||||
public:
|
||||
typedef typename property_traits<IndexMap>::key_type key_type;
|
||||
typedef T value_type;
|
||||
typedef typename std::iterator_traits<
|
||||
typename std::vector<T>::iterator >::reference reference;
|
||||
typedef boost::lvalue_property_map_tag category;
|
||||
|
||||
vector_property_map(const IndexMap& index = IndexMap())
|
||||
: store(new std::vector<T>()), index(index)
|
||||
{}
|
||||
|
||||
vector_property_map(unsigned initial_size,
|
||||
const IndexMap& index = IndexMap())
|
||||
: store(new std::vector<T>(initial_size)), index(index)
|
||||
{}
|
||||
|
||||
typename std::vector<T>::iterator storage_begin()
|
||||
{
|
||||
return store->begin();
|
||||
}
|
||||
|
||||
typename std::vector<T>::iterator storage_end()
|
||||
{
|
||||
return store->end();
|
||||
}
|
||||
|
||||
typename std::vector<T>::const_iterator storage_begin() const
|
||||
{
|
||||
return store->begin();
|
||||
}
|
||||
|
||||
typename std::vector<T>::const_iterator storage_end() const
|
||||
{
|
||||
return store->end();
|
||||
}
|
||||
|
||||
IndexMap& get_index_map() { return index; }
|
||||
const IndexMap& get_index_map() const { return index; }
|
||||
|
||||
public:
|
||||
// Copy ctor absent, default semantics is OK.
|
||||
// Assignment operator absent, default semantics is OK.
|
||||
// CONSIDER: not sure that assignment to 'index' is correct.
|
||||
|
||||
reference operator[](const key_type& v) const {
|
||||
typename property_traits<IndexMap>::value_type i = get(index, v);
|
||||
if (static_cast<unsigned>(i) >= store->size()) {
|
||||
store->resize(i + 1, T());
|
||||
}
|
||||
return (*store)[i];
|
||||
}
|
||||
private:
|
||||
// Conceptually, we have a vector of infinite size. For practical
|
||||
// purposes, we start with an empty vector and grow it as needed.
|
||||
// Note that we cannot store pointer to vector here -- we cannot
|
||||
// store pointer to data, because if copy of property map resizes
|
||||
// the vector, the pointer to data will be invalidated.
|
||||
// I wonder if class 'pmap_ref' is simply needed.
|
||||
shared_ptr< std::vector<T> > store;
|
||||
IndexMap index;
|
||||
};
|
||||
|
||||
template<typename T, typename IndexMap>
|
||||
vector_property_map<T, IndexMap>
|
||||
make_vector_property_map(IndexMap index)
|
||||
{
|
||||
return vector_property_map<T, IndexMap>(index);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_GRAPH_USE_MPI
|
||||
#include <boost/property_map/parallel/distributed_property_map.hpp>
|
||||
#include <boost/property_map/parallel/local_property_map.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
/** Distributed vector property map.
|
||||
*
|
||||
* This specialization of @ref vector_property_map builds a
|
||||
* distributed vector property map given the local index maps
|
||||
* generated by distributed graph types that automatically have index
|
||||
* properties.
|
||||
*
|
||||
* This specialization is useful when creating external distributed
|
||||
* property maps via the same syntax used to create external
|
||||
* sequential property maps.
|
||||
*/
|
||||
template<typename T, typename ProcessGroup, typename GlobalMap,
|
||||
typename StorageMap>
|
||||
class vector_property_map<T,
|
||||
local_property_map<ProcessGroup, GlobalMap,
|
||||
StorageMap> >
|
||||
: public parallel::distributed_property_map<
|
||||
ProcessGroup, GlobalMap, vector_property_map<T, StorageMap> >
|
||||
{
|
||||
typedef vector_property_map<T, StorageMap> local_iterator_map;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
local_iterator_map> inherited;
|
||||
|
||||
typedef local_property_map<ProcessGroup, GlobalMap, StorageMap> index_map_type;
|
||||
|
||||
public:
|
||||
vector_property_map(const index_map_type& index = index_map_type())
|
||||
: inherited(index.process_group(), index.global(),
|
||||
local_iterator_map(index.base())) { }
|
||||
|
||||
vector_property_map(unsigned inital_size,
|
||||
const index_map_type& index = index_map_type())
|
||||
: inherited(index.process_group(), index.global(),
|
||||
local_iterator_map(inital_size, index.base())) { }
|
||||
};
|
||||
|
||||
/** Distributed vector property map.
|
||||
*
|
||||
* This specialization of @ref vector_property_map builds a
|
||||
* distributed vector property map given the local index maps
|
||||
* generated by distributed graph types that automatically have index
|
||||
* properties.
|
||||
*
|
||||
* This specialization is useful when creating external distributed
|
||||
* property maps via the same syntax used to create external
|
||||
* sequential property maps.
|
||||
*/
|
||||
template<typename T, typename ProcessGroup, typename GlobalMap,
|
||||
typename StorageMap>
|
||||
class vector_property_map<
|
||||
T,
|
||||
parallel::distributed_property_map<
|
||||
ProcessGroup,
|
||||
GlobalMap,
|
||||
StorageMap
|
||||
>
|
||||
>
|
||||
: public parallel::distributed_property_map<
|
||||
ProcessGroup, GlobalMap, vector_property_map<T, StorageMap> >
|
||||
{
|
||||
typedef vector_property_map<T, StorageMap> local_iterator_map;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
local_iterator_map> inherited;
|
||||
|
||||
typedef parallel::distributed_property_map<ProcessGroup, GlobalMap,
|
||||
StorageMap>
|
||||
index_map_type;
|
||||
|
||||
public:
|
||||
vector_property_map(const index_map_type& index = index_map_type())
|
||||
: inherited(index.process_group(), index.global(),
|
||||
local_iterator_map(index.base())) { }
|
||||
|
||||
vector_property_map(unsigned inital_size,
|
||||
const index_map_type& index = index_map_type())
|
||||
: inherited(index.process_group(), index.global(),
|
||||
local_iterator_map(inital_size, index.base())) { }
|
||||
};
|
||||
|
||||
}
|
||||
#endif // BOOST_GRAPH_USE_MPI
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user