]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | [auto_generated] | |
3 | boost/numeric/odeint/external/mpi/mpi_state.hpp | |
4 | ||
5 | [begin_description] | |
6 | A generic split state, storing partial data on each node. | |
7 | [end_description] | |
8 | ||
9 | Copyright 2013 Karsten Ahnert | |
10 | Copyright 2013 Mario Mulansky | |
11 | Copyright 2013 Pascal Germroth | |
12 | ||
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) | |
16 | */ | |
17 | ||
18 | ||
19 | #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED | |
20 | #define BOOST_NUMERIC_ODEINT_EXTERNAL_MPI_MPI_STATE_HPP_INCLUDED | |
21 | ||
22 | #include <vector> | |
23 | #include <algorithm> | |
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> | |
31 | ||
32 | namespace boost { | |
33 | namespace numeric { | |
34 | namespace odeint { | |
35 | ||
36 | /** \brief A container which has its contents distributed among the nodes. | |
37 | */ | |
38 | template< class InnerState > | |
39 | struct mpi_state | |
40 | { | |
41 | typedef InnerState value_type; | |
42 | ||
43 | // the node's local data. | |
44 | InnerState m_data; | |
45 | ||
46 | boost::mpi::communicator world; | |
47 | ||
48 | mpi_state() {} | |
49 | mpi_state(boost::mpi::communicator comm) : world(comm) {} | |
50 | ||
51 | inline InnerState &operator()() { return m_data; } | |
52 | inline const InnerState &operator()() const { return m_data; } | |
53 | }; | |
54 | ||
55 | ||
56 | ||
57 | ||
58 | template< class InnerState > | |
59 | struct is_resizeable< mpi_state< InnerState > > | |
60 | : is_resizeable< InnerState > { }; | |
61 | ||
62 | ||
63 | template< class InnerState1 , class InnerState2 > | |
64 | struct same_size_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > > | |
65 | { | |
66 | static bool same_size( const mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y ) | |
67 | { | |
68 | const bool local = boost::numeric::odeint::same_size(x(), y()); | |
69 | return boost::mpi::all_reduce(x.world, local, mpi::bitwise_and<bool>()); | |
70 | } | |
71 | }; | |
72 | ||
73 | ||
74 | template< class InnerState1 , class InnerState2 > | |
75 | struct resize_impl< mpi_state< InnerState1 > , mpi_state< InnerState2 > > | |
76 | { | |
77 | static void resize( mpi_state< InnerState1 > &x , const mpi_state< InnerState2 > &y ) | |
78 | { | |
79 | // resize local parts on each node. | |
80 | boost::numeric::odeint::resize(x(), y()); | |
81 | } | |
82 | }; | |
83 | ||
84 | ||
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 > > | |
88 | { | |
89 | static void copy( const mpi_state< InnerState1 > &from , mpi_state< InnerState2 > &to ) | |
90 | { | |
91 | // copy local parts on each node. | |
92 | boost::numeric::odeint::copy(from(), to()); | |
93 | } | |
94 | }; | |
95 | ||
96 | ||
97 | ||
98 | /** \brief Use `mpi_algebra` for `mpi_state`. */ | |
99 | template< class InnerState > | |
100 | struct algebra_dispatcher< mpi_state< InnerState > > | |
101 | { | |
102 | typedef mpi_nested_algebra< | |
103 | typename algebra_dispatcher< InnerState >::algebra_type | |
104 | > algebra_type; | |
105 | }; | |
106 | ||
107 | ||
108 | } | |
109 | } | |
110 | } | |
111 | ||
112 | ||
113 | #endif |