mpi_state.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/external/mpi/mpi_state.hpp
  4. [begin_description]
  5. A generic split state, storing partial data on each node.
  6. [end_description]
  7. Copyright 2013 Karsten Ahnert
  8. Copyright 2013 Mario Mulansky
  9. Copyright 2013 Pascal Germroth
  10. Distributed under the Boost Software License, Version 1.0.
  11. (See accompanying file LICENSE_1_0.txt or
  12. copy at http://www.boost.org/LICENSE_1_0.txt)
  13. */
  14. #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
  15. #define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED
  16. #include <vector>
  17. #include <algorithm>
  18. #include <boost/mpi.hpp>
  19. #include <boost/numeric/odeint/util/copy.hpp>
  20. #include <boost/numeric/odeint/util/split.hpp>
  21. #include <boost/numeric/odeint/util/resize.hpp>
  22. #include <boost/numeric/odeint/util/same_size.hpp>
  23. #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
  24. #include <boost/numeric/odeint/external/mpi/mpi_nested_algebra.hpp>
  25. namespace boost {
  26. namespace numeric {
  27. namespace odeint {
  28. /** \brief A container which has its contents distributed among the nodes.
  29. */
  30. template< class InnerState >
  31. struct mpi_state
  32. {
  33. typedef InnerState value_type;
  34. // the node's local data.
  35. InnerState m_data;
  36. boost::mpi::communicator world;
  37. mpi_state() {}
  38. mpi_state(boost::mpi::communicator comm) : world(comm) {}
  39. inline InnerState &operator()() { return m_data; }
  40. inline const InnerState &operator()() const { return m_data; }
  41. };
  42. template< class InnerState >
  43. struct is_resizeable< mpi_state< InnerState > >
  44. : is_resizeable< InnerState > { };
  45. template< class InnerState1 , class InnerState2 >
  46. struct same_size_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
  47. {
  48. static bool same_size( const mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
  49. {
  50. const bool local = boost::numeric::odeint::same_size(x(), y());
  51. return boost::mpi::all_reduce(x.world, local, mpi::bitwise_and<bool>());
  52. }
  53. };
  54. template< class InnerState1 , class InnerState2 >
  55. struct resize_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
  56. {
  57. static void resize( mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y )
  58. {
  59. // resize local parts on each node.
  60. boost::numeric::odeint::resize(x(), y());
  61. }
  62. };
  63. /** \brief Copy data between mpi_states of same size. */
  64. template< class InnerState1 , class InnerState2 >
  65. struct copy_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > >
  66. {
  67. static void copy( const mpi_state< InnerState1 > &from , mpi_state< InnerState2 > &to )
  68. {
  69. // copy local parts on each node.
  70. boost::numeric::odeint::copy(from(), to());
  71. }
  72. };
  73. /** \brief Use `mpi_algebra` for `mpi_state`. */
  74. template< class InnerState >
  75. struct algebra_dispatcher< mpi_state< InnerState > >
  76. {
  77. typedef mpi_nested_algebra<
  78. typename algebra_dispatcher< InnerState >::algebra_type
  79. > algebra_type;
  80. };
  81. }
  82. }
  83. }
  84. #endif