From 1f8e2cc889c70196bb20e0d6c3adb89cb52dfb40 Mon Sep 17 00:00:00 2001 From: Arnaud Becheler <8360330+Becheler@users.noreply.github.com> Date: Tue, 1 Sep 2026 13:57:57 +0200 Subject: [PATCH] refactor: move distributed awareness from BGL to PBGL --- .../distributed/detail/property_serialize.hpp | 86 +++++++++++++++++++ .../graph/distributed/filtered_graph.hpp | 1 + .../distributed/fruchterman_reingold.hpp | 1 + .../distributed/rmat_graph_generator.hpp | 1 + .../graph/distributed/strong_components.hpp | 1 + include/boost/graph/use_mpi.hpp | 53 ++++++++++++ 6 files changed, 143 insertions(+) create mode 100644 include/boost/graph/distributed/detail/property_serialize.hpp create mode 100644 include/boost/graph/use_mpi.hpp diff --git a/include/boost/graph/distributed/detail/property_serialize.hpp b/include/boost/graph/distributed/detail/property_serialize.hpp new file mode 100644 index 00000000..a5e2ef8c --- /dev/null +++ b/include/boost/graph/distributed/detail/property_serialize.hpp @@ -0,0 +1,86 @@ +// Copyright (C) Jeremy Siek 2006. +// Copyright (C) 2026 Arnaud Becheler. + +// 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) + +// Serialization traits for boost::property<> and boost::no_property when a +// Parallel BGL adjacency_list is sent over MPI. + +#ifndef BOOST_GRAPH_DISTRIBUTED_DETAIL_PROPERTY_SERIALIZE_HPP +#define BOOST_GRAPH_DISTRIBUTED_DETAIL_PROPERTY_SERIALIZE_HPP + +#include +#include +#include +#include +#include +#include +#include + +// Setting the serialization properties of boost::property<> and +// boost::no_property to is_bitwise_serializable, object_serializable, +// track_never only when BOOST_GRAPH_USE_MPI is defined is dubious. +// +// This changes the serialization format of these classes, and hence +// of boost::adjacency_list, depending on whether BOOST_GRAPH_USE_MPI +// is defined. +// +// These serialization properties should probably be set in either case. +// +// Unfortunately, doing that now will change the serialization format +// of boost::adjacency_list in the non-MPI case, and could potentially +// break software that reads files serialized with an older release. + +namespace boost +{ + +namespace mpi +{ + + // forward declaration, to avoid including mpi + template < typename T > struct is_mpi_datatype; + + template < typename Tag, typename T, typename Base > + struct is_mpi_datatype< property< Tag, T, Base > > + : mpl::and_< is_mpi_datatype< T >, is_mpi_datatype< Base > > + { + }; +} + +namespace serialization +{ + template < typename Tag, typename T, typename Base > + struct is_bitwise_serializable< property< Tag, T, Base > > + : mpl::and_< is_bitwise_serializable< T >, is_bitwise_serializable< Base > > + { + }; + + template < typename Tag, typename T, typename Base > + struct implementation_level< property< Tag, T, Base > > + : mpl::int_< object_serializable > + { + }; + + template < typename Tag, typename T, typename Base > + struct tracking_level< property< Tag, T, Base > > : mpl::int_< track_never > + { + }; + +} + +namespace mpi +{ + template <> struct is_mpi_datatype< boost::no_property > : mpl::true_ + { + }; +} + +} // end namespace boost + +BOOST_IS_BITWISE_SERIALIZABLE(boost::no_property) +BOOST_CLASS_IMPLEMENTATION(boost::no_property, object_serializable) +BOOST_CLASS_TRACKING(boost::no_property, track_never) + +#endif // BOOST_GRAPH_DISTRIBUTED_DETAIL_PROPERTY_SERIALIZE_HPP diff --git a/include/boost/graph/distributed/filtered_graph.hpp b/include/boost/graph/distributed/filtered_graph.hpp index 9677e4dd..3c74f817 100644 --- a/include/boost/graph/distributed/filtered_graph.hpp +++ b/include/boost/graph/distributed/filtered_graph.hpp @@ -15,6 +15,7 @@ #endif #include +#include #include namespace boost { diff --git a/include/boost/graph/distributed/fruchterman_reingold.hpp b/include/boost/graph/distributed/fruchterman_reingold.hpp index a89aea3d..0b78d8f7 100644 --- a/include/boost/graph/distributed/fruchterman_reingold.hpp +++ b/include/boost/graph/distributed/fruchterman_reingold.hpp @@ -14,6 +14,7 @@ #endif #include +#include namespace boost { namespace graph { namespace distributed { diff --git a/include/boost/graph/distributed/rmat_graph_generator.hpp b/include/boost/graph/distributed/rmat_graph_generator.hpp index dec8250d..ce985a92 100644 --- a/include/boost/graph/distributed/rmat_graph_generator.hpp +++ b/include/boost/graph/distributed/rmat_graph_generator.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace boost { diff --git a/include/boost/graph/distributed/strong_components.hpp b/include/boost/graph/distributed/strong_components.hpp index 139f39d5..17e25aea 100644 --- a/include/boost/graph/distributed/strong_components.hpp +++ b/include/boost/graph/distributed/strong_components.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/graph/use_mpi.hpp b/include/boost/graph/use_mpi.hpp new file mode 100644 index 00000000..074d6cd3 --- /dev/null +++ b/include/boost/graph/use_mpi.hpp @@ -0,0 +1,53 @@ +// Copyright (C) 2004-2009 The Trustees of Indiana University. +// Copyright (C) 2026 Arnaud Becheler. + +// 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: Nick Edmonds +// Andrew Lumsdaine + +#ifndef BOOST_GRAPH_USE_MPI_HPP +#define BOOST_GRAPH_USE_MPI_HPP + +#define BOOST_GRAPH_USE_MPI + +#include + +namespace boost +{ +template < typename G > struct graph_traits; +template < typename T, typename Tag, typename Base > struct bgl_named_params; + +namespace detail +{ + // Declared before breadth_first_search.hpp so bfs_dispatch finds it by + // ordinary lookup. Defined in distributed/breadth_first_search.hpp. + template < class DistributedGraph, class ColorMap, class BFSVisitor, + class P, class T, class R > + void bfs_helper(DistributedGraph& g, + typename graph_traits< DistributedGraph >::vertex_descriptor s, + ColorMap color, BFSVisitor vis, + const bgl_named_params< P, T, R >& params, boost::mpl::true_); +} +} + +// property<> serialization traits, needed wherever MPI serialization happens. +#include + +// Distributed algorithm overloads. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif // BOOST_GRAPH_USE_MPI_HPP