This commit is contained in:
2026-03-23 20:54:41 +08:00
commit e13b3650e9
4596 changed files with 1015768 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
/*
[auto_generated]
boost/numeric/odeint/external/mpi/mpi.hpp
[begin_description]
Wrappers for MPI.
[end_description]
Copyright 2013 Karsten Ahnert
Copyright 2013 Mario Mulansky
Copyright 2013 Pascal Germroth
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)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_HPP_INCLUDED
#include <boost/numeric/odeint/external/mpi/mpi_vector_state.hpp>
#include <boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp>
#endif

View File

@@ -0,0 +1,62 @@
/*
[auto_generated]
boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp
[begin_description]
Nested parallelized algebra for MPI.
[end_description]
Copyright 2013 Karsten Ahnert
Copyright 2013 Mario Mulansky
Copyright 2013 Pascal Germroth
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)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_NESTED_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_NESTED_ALGEBRA_HPP_INCLUDED
#include <boost/numeric/odeint/algebra/norm_result_type.hpp>
#include <boost/numeric/odeint/util/n_ary_helper.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/** \brief MPI-parallelized algebra, wrapping another algebra.
*/
template< class InnerAlgebra >
struct mpi_nested_algebra
{
// execute the InnerAlgebra on each node's local data.
#define BOOST_ODEINT_GEN_BODY(n) \
InnerAlgebra::for_each##n( \
BOOST_PP_ENUM_BINARY_PARAMS(n, s, () BOOST_PP_INTERCEPT) , \
op \
);
BOOST_ODEINT_GEN_FOR_EACH(BOOST_ODEINT_GEN_BODY)
#undef BOOST_ODEINT_GEN_BODY
template< class NestedState >
static typename norm_result_type< typename NestedState::value_type >::type norm_inf( const NestedState &s )
{
typedef typename norm_result_type< typename NestedState::value_type >::type result_type;
// local maximum
result_type value = InnerAlgebra::norm_inf( s() );
// global maximum
return boost::mpi::all_reduce(s.world, value, boost::mpi::maximum<result_type>());
}
};
}
}
}
#endif

View File

@@ -0,0 +1,113 @@
/*
[auto_generated]
boost/numeric/odeint/external/mpi/mpi_state.hpp
[begin_description]
A generic split state, storing partial data on each node.
[end_description]
Copyright 2013 Karsten Ahnert
Copyright 2013 Mario Mulansky
Copyright 2013 Pascal Germroth
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)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
#include <vector>
#include <algorithm>
#include <boost/mpi.hpp>
#include <boost/numeric/odeint/util/copy.hpp>
#include <boost/numeric/odeint/util/split.hpp>
#include <boost/numeric/odeint/util/resize.hpp>
#include <boost/numeric/odeint/util/same_size.hpp>
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
#include <boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/** \brief A container which has its contents distributed among the nodes.
*/
template< class InnerState >
struct mpi_state
{
typedef InnerState value_type;
// the node's local data.
InnerState m_data;
boost::mpi::communicator world;
mpi_state() {}
mpi_state(boost::mpi::communicator comm) : world(comm) {}
inline InnerState &operator()() { return m_data; }
inline const InnerState &operator()() const { return m_data; }
};
template< class InnerState >
struct is_resizeable< mpi_state< InnerState > >
: is_resizeable< InnerState > { };
template< class InnerState1 , class InnerState2 >
struct same_size_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
{
static bool same_size( const mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
{
const bool local = boost::numeric::odeint::same_size(x(), y());
return boost::mpi::all_reduce(x.world, local, mpi::bitwise_and<bool>());
}
};
template< class InnerState1 , class InnerState2 >
struct resize_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
{
static void resize( mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
{
// resize local parts on each node.
boost::numeric::odeint::resize(x(), y());
}
};
/** \brief Copy data between mpi_states of same size. */
template< class InnerState1 , class InnerState2 >
struct copy_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
{
static void copy( const mpi_state< InnerState1 > &from , mpi_state< InnerState2 > &to )
{
// copy local parts on each node.
boost::numeric::odeint::copy(from(), to());
}
};
/** \brief Use `mpi_algebra` for `mpi_state`. */
template< class InnerState >
struct algebra_dispatcher< mpi_state< InnerState > >
{
typedef mpi_nested_algebra<
typename algebra_dispatcher< InnerState >::algebra_type
> algebra_type;
};
}
}
}
#endif

View File

@@ -0,0 +1,95 @@
/*
[auto_generated]
boost/numeric/odeint/external/mpi/mpi_vector_state.hpp
[begin_description]
Copying a container from/to an mpi_state splits/joins it.
[end_description]
Copyright 2013 Karsten Ahnert
Copyright 2013 Mario Mulansky
Copyright 2013 Pascal Germroth
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)
*/
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_VECTOR_STATE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_VECTOR_STATE_HPP_INCLUDED
#include <vector>
#include <algorithm>
#include <boost/mpi.hpp>
#include <boost/numeric/odeint/util/copy.hpp>
#include <boost/numeric/odeint/util/split_adaptor.hpp>
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
#include <boost/numeric/odeint/external/mpi/mpi_state.hpp>
#include <boost/numeric/odeint/tools/assert.hpp>
namespace boost {
namespace numeric {
namespace odeint {
/** \brief Split data from some container on node 0 to the slaves.
* Source must be a model of Random Access Range. */
template< class Source , class InnerState >
struct split_impl< Source, mpi_state< InnerState >,
typename boost::enable_if< boost::has_range_const_iterator<Source> >::type >
{
typedef typename boost::range_iterator<const Source>::type iterator;
static void split( const Source &from, mpi_state< InnerState > &to )
{
std::vector< InnerState > pieces;
if(to.world.rank() == 0) {
const size_t num = static_cast<size_t>(to.world.size());
pieces.resize(num);
for(size_t i = 0 ; i < num ; i++) {
iterator_range<iterator> part = detail::make_split_range(from, i, num);
boost::numeric::odeint::resize(pieces[i], part);
boost::numeric::odeint::copy(part, pieces[i]);
}
}
// send to nodes
boost::mpi::scatter(to.world, pieces, to(), 0);
}
};
/** \brief Merge data from an mpi_state to some container on node 0.
* Target must be a model Single Pass Range. */
template< class Target, class InnerState >
struct unsplit_impl< mpi_state< InnerState >, Target,
typename boost::enable_if< boost::has_range_iterator<Target> >::type >
{
typedef typename boost::range_iterator<Target>::type iterator;
static void unsplit( const mpi_state< InnerState > &from , Target &to )
{
std::vector< InnerState > pieces;
// send data to root
boost::mpi::gather(from.world, from(), pieces, 0);
if(from.world.rank() == 0) {
// check target size
size_t total_size = 0;
for(size_t i = 0 ; i < pieces.size() ; i++)
total_size += boost::size(pieces[i]);
BOOST_NUMERIC_ODEINT_ASSERT( total_size <= boost::size(to) );
// copy parts
iterator out = boost::begin(to);
for(size_t i = 0 ; i < pieces.size() ; i++)
out = boost::copy(pieces[i], out);
}
}
};
}
}
}
#endif