3 boost/numeric/odeint/external/mpi/mpi_state.hpp
6 A generic split state, storing partial data on each node.
9 Copyright 2013 Karsten Ahnert
10 Copyright 2013 Mario Mulansky
11 Copyright 2013 Pascal Germroth
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
24 #include <boost/mpi.hpp>
25 #include <boost/numeric/odeint/util/copy.hpp>
26 #include <boost/numeric/odeint/util/split.hpp>
27 #include <boost/numeric/odeint/util/resize.hpp>
28 #include <boost/numeric/odeint/util/same_size.hpp>
29 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
30 #include <boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp>
36 /** \brief A container which has its contents distributed among the nodes.
38 template< class InnerState >
41 typedef InnerState value_type;
43 // the node's local data.
46 boost::mpi::communicator world;
49 mpi_state(boost::mpi::communicator comm) : world(comm) {}
51 inline InnerState &operator()() { return m_data; }
52 inline const InnerState &operator()() const { return m_data; }
58 template< class InnerState >
59 struct is_resizeable< mpi_state< InnerState > >
60 : is_resizeable< InnerState > { };
63 template< class InnerState1 , class InnerState2 >
64 struct same_size_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
66 static bool same_size( const mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
68 const bool local = boost::numeric::odeint::same_size(x(), y());
69 return boost::mpi::all_reduce(x.world, local, mpi::bitwise_and<bool>());
74 template< class InnerState1 , class InnerState2 >
75 struct resize_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
77 static void resize( mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
79 // resize local parts on each node.
80 boost::numeric::odeint::resize(x(), y());
85 /** \brief Copy data between mpi_states of same size. */
86 template< class InnerState1 , class InnerState2 >
87 struct copy_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
89 static void copy( const mpi_state< InnerState1 > &from , mpi_state< InnerState2 > &to )
91 // copy local parts on each node.
92 boost::numeric::odeint::copy(from(), to());
98 /** \brief Use `mpi_algebra` for `mpi_state`. */
99 template< class InnerState >
100 struct algebra_dispatcher< mpi_state< InnerState > >
102 typedef mpi_nested_algebra<
103 typename algebra_dispatcher< InnerState >::algebra_type