File indexing completed on 2025-01-18 09:42:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
0021
0022 #include <vector>
0023 #include <algorithm>
0024 #include <boost/mpi.hpp>
0025 #include <boost/numeric/odeint/util/copy.hpp>
0026 #include <boost/numeric/odeint/util/split.hpp>
0027 #include <boost/numeric/odeint/util/resize.hpp>
0028 #include <boost/numeric/odeint/util/same_size.hpp>
0029 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
0030 #include <boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp>
0031
0032 namespace boost {
0033 namespace numeric {
0034 namespace odeint {
0035
0036
0037
0038 template< class InnerState >
0039 struct mpi_state
0040 {
0041 typedef InnerState value_type;
0042
0043
0044 InnerState m_data;
0045
0046 boost::mpi::communicator world;
0047
0048 mpi_state() {}
0049 mpi_state(boost::mpi::communicator comm) : world(comm) {}
0050
0051 inline InnerState &operator()() { return m_data; }
0052 inline const InnerState &operator()() const { return m_data; }
0053 };
0054
0055
0056
0057
0058 template< class InnerState >
0059 struct is_resizeable< mpi_state< InnerState > >
0060 : is_resizeable< InnerState > { };
0061
0062
0063 template< class InnerState1 , class InnerState2 >
0064 struct same_size_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
0065 {
0066 static bool same_size( const mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
0067 {
0068 const bool local = boost::numeric::odeint::same_size(x(), y());
0069 return boost::mpi::all_reduce(x.world, local, mpi::bitwise_and<bool>());
0070 }
0071 };
0072
0073
0074 template< class InnerState1 , class InnerState2 >
0075 struct resize_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
0076 {
0077 static void resize( mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
0078 {
0079
0080 boost::numeric::odeint::resize(x(), y());
0081 }
0082 };
0083
0084
0085
0086 template< class InnerState1 , class InnerState2 >
0087 struct copy_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
0088 {
0089 static void copy( const mpi_state< InnerState1 > &from , mpi_state< InnerState2 > &to )
0090 {
0091
0092 boost::numeric::odeint::copy(from(), to());
0093 }
0094 };
0095
0096
0097
0098
0099 template< class InnerState >
0100 struct algebra_dispatcher< mpi_state< InnerState > >
0101 {
0102 typedef mpi_nested_algebra<
0103 typename algebra_dispatcher< InnerState >::algebra_type
0104 > algebra_type;
0105 };
0106
0107
0108 }
0109 }
0110 }
0111
0112
0113 #endif