schwz  Generated automatically from develop
communicate.hpp (cd61077)
1 /*******************************<SCHWARZ LIB LICENSE>***********************
2 Copyright (c) 2019, the SCHWARZ LIB authors
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************<SCHWARZ LIB LICENSE>*************************/
32 
33 #ifndef communicate_hpp
34 #define communicate_hpp
35 
36 
37 #include <memory>
38 
39 
40 #include <mpi.h>
41 
42 
43 #include "initialization.hpp"
44 
45 
46 namespace schwz {
47 
48 
59 template <typename ValueType, typename IndexType, typename MixedValueType>
60 class Communicate {
61 public:
62  friend class Initialize<ValueType, IndexType>;
63 
67  struct comm_struct {
68  public:
73 
78 
82  std::shared_ptr<gko::Array<IndexType>> neighbors_in;
83 
87  std::shared_ptr<gko::Array<IndexType>> neighbors_out;
88 
93  std::vector<bool> is_local_neighbor;
98 
103 
107  std::shared_ptr<gko::Array<IndexType>> local_neighbors_in;
108 
112  std::shared_ptr<gko::Array<IndexType>> local_neighbors_out;
113 
120  std::shared_ptr<gko::Array<IndexType *>> global_put;
121 
125  std::shared_ptr<gko::Array<IndexType *>> local_put;
126 
134  std::shared_ptr<gko::Array<IndexType *>> global_get;
135 
139  std::shared_ptr<gko::Array<IndexType *>> local_get;
140 
144  std::vector<IndexType> send;
145 
149  std::vector<IndexType> recv;
150 
154  std::shared_ptr<gko::Array<IndexType>> window_ids;
155 
159  std::shared_ptr<gko::Array<IndexType>> windows_from;
160 
164  std::shared_ptr<gko::Array<IndexType>> windows_to;
165 
169  std::shared_ptr<gko::Array<MPI_Request>> put_request;
170 
174  std::shared_ptr<gko::Array<MPI_Request>> get_request;
175 
180  std::shared_ptr<gko::matrix::Dense<ValueType>> send_buffer;
181 
186  std::shared_ptr<gko::matrix::Dense<MixedValueType>> mixedt_send_buffer;
187 
192  std::shared_ptr<gko::matrix::Dense<ValueType>> recv_buffer;
193 
198  std::shared_ptr<gko::matrix::Dense<MixedValueType>> mixedt_recv_buffer;
199 
203  std::shared_ptr<gko::Array<IndexType>> get_displacements;
204 
208  std::shared_ptr<gko::Array<IndexType>> put_displacements;
209 
214 
219 
223  MPI_Win window_x;
224  };
226 
230  virtual void setup_comm_buffers() = 0;
231 
240  virtual void setup_windows(
241  const Settings &settings,
242  const Metadata<ValueType, IndexType> &metadata,
243  std::shared_ptr<gko::matrix::Dense<ValueType>> &main_buffer) = 0;
244 
253  virtual void exchange_boundary(
254  const Settings &settings,
255  const Metadata<ValueType, IndexType> &metadata,
256  std::shared_ptr<gko::matrix::Dense<ValueType>> &global_solution) = 0;
257 
267  const Settings &settings,
268  const Metadata<ValueType, IndexType> &metadata,
269  const std::shared_ptr<gko::matrix::Dense<ValueType>> &local_vector,
270  std::shared_ptr<gko::matrix::Dense<ValueType>> &global_vector);
271 
287  virtual void update_boundary(
288  const Settings &settings,
289  const Metadata<ValueType, IndexType> &metadata,
290  std::shared_ptr<gko::matrix::Dense<ValueType>> &local_solution,
291  const std::shared_ptr<gko::matrix::Dense<ValueType>> &local_rhs,
292  const std::shared_ptr<gko::matrix::Dense<ValueType>> &global_solution,
293  const std::shared_ptr<gko::matrix::Csr<ValueType, IndexType>>
294  &interface_matrix) = 0;
295 
299  void clear(Settings &settings);
300 };
301 
302 
303 } // namespace schwz
304 
305 
306 #endif // communicate.hpp
std::vector< IndexType > recv
The number of elements being sent to each subdomain.
Definition: communicate.hpp:149
int local_num_neighbors_in
The number of neighbors this subdomain has to receive data from.
Definition: communicate.hpp:97
std::shared_ptr< gko::Array< IndexType > > neighbors_out
The neighbors this subdomain has to send data to.
Definition: communicate.hpp:87
The solver metadata struct.
Definition: settings.hpp:319
MPI_Win window_recv_buffer
The RDMA window for the recv buffer.
Definition: communicate.hpp:213
virtual void exchange_boundary(const Settings &settings, const Metadata< ValueType, IndexType > &metadata, std::shared_ptr< gko::matrix::Dense< ValueType >> &global_solution)=0
Exchanges the elements of the solution vector.
Definition: communicate.cpp:50
virtual void setup_windows(const Settings &settings, const Metadata< ValueType, IndexType > &metadata, std::shared_ptr< gko::matrix::Dense< ValueType >> &main_buffer)=0
Sets up the windows needed for the asynchronous communication.
Definition: communicate.cpp:44
std::shared_ptr< gko::Array< IndexType > > windows_from
The RDMA window ids to receive data from.
Definition: communicate.hpp:159
The communication struct used to store the communication data.
Definition: communicate.hpp:67
void local_to_global_vector(const Settings &settings, const Metadata< ValueType, IndexType > &metadata, const std::shared_ptr< gko::matrix::Dense< ValueType >> &local_vector, std::shared_ptr< gko::matrix::Dense< ValueType >> &global_vector)
Transforms data from a local vector to a global vector.
Definition: communicate.cpp:65
std::shared_ptr< gko::Array< IndexType * > > global_put
The array containing the number of elements that each subdomain sends from the other.
Definition: communicate.hpp:120
std::shared_ptr< gko::Array< IndexType > > neighbors_in
The neighbors this subdomain has to receive data from.
Definition: communicate.hpp:82
std::shared_ptr< gko::Array< MPI_Request > > get_request
The get request array.
Definition: communicate.hpp:174
std::shared_ptr< gko::Array< IndexType > > windows_to
The RDMA window ids to send data to.
Definition: communicate.hpp:164
std::shared_ptr< gko::matrix::Dense< MixedValueType > > mixedt_recv_buffer
The mixed precision recv buffer used for the actual communication for both one-sided and two-sided...
Definition: communicate.hpp:198
The communication class that provides the methods for the communication between the subdomains...
Definition: communicate.hpp:60
std::vector< IndexType > send
The number of elements being sent to each subdomain.
Definition: communicate.hpp:144
int num_neighbors_out
The number of neighbors this subdomain has to send data to.
Definition: communicate.hpp:77
std::shared_ptr< gko::Array< IndexType > > put_displacements
The displacements for the sending of the buffer.
Definition: communicate.hpp:208
std::shared_ptr< gko::matrix::Dense< MixedValueType > > mixedt_send_buffer
The mixed send buffer used for the actual communication for both one-sided and two-sided.
Definition: communicate.hpp:186
std::vector< bool > is_local_neighbor
The bool vector which is true if the neighbors of a subdomain are in one node.
Definition: communicate.hpp:93
The struct that contains the solver settings and the parameters to be set by the user.
Definition: settings.hpp:77
int local_num_neighbors_out
The number of neighbors this subdomain has to send data to.
Definition: communicate.hpp:102
std::shared_ptr< gko::Array< IndexType > > local_neighbors_in
The neighbors this subdomain has to receive data from.
Definition: communicate.hpp:107
virtual void setup_comm_buffers()=0
Sets up the communication buffers needed for the boundary exchange.
Definition: communicate.cpp:40
MPI_Win window_x
The RDMA window for the solution vector.
Definition: communicate.hpp:223
std::shared_ptr< gko::Array< IndexType * > > global_get
The array containing the number of elements that each subdomain gets from the other.
Definition: communicate.hpp:134
void clear(Settings &settings)
Clears the data.
Definition: communicate.cpp:97
std::shared_ptr< gko::Array< MPI_Request > > put_request
The put request array.
Definition: communicate.hpp:169
std::shared_ptr< gko::Array< IndexType > > local_neighbors_out
The neighbors this subdomain has to send data to.
Definition: communicate.hpp:112
The Schwarz wrappers namespace.
Definition: comm_helpers.hpp:49
The initialization class that provides methods for initialization of the solver.
Definition: initialization.hpp:72
MPI_Win window_send_buffer
The RDMA window for the send buffer.
Definition: communicate.hpp:218
int num_neighbors_in
The number of neighbors this subdomain has to receive data from.
Definition: communicate.hpp:72
std::shared_ptr< gko::Array< IndexType > > get_displacements
The displacements for the receiving of the buffer.
Definition: communicate.hpp:203
std::shared_ptr< gko::matrix::Dense< ValueType > > recv_buffer
The recv buffer used for the actual communication for both one-sided and two-sided (always allocated)...
Definition: communicate.hpp:192
std::shared_ptr< gko::matrix::Dense< ValueType > > send_buffer
The send buffer used for the actual communication for both one-sided and two-sided (always allocated)...
Definition: communicate.hpp:180
std::shared_ptr< gko::Array< IndexType > > window_ids
The RDMA window ids.
Definition: communicate.hpp:154
virtual void update_boundary(const Settings &settings, const Metadata< ValueType, IndexType > &metadata, std::shared_ptr< gko::matrix::Dense< ValueType >> &local_solution, const std::shared_ptr< gko::matrix::Dense< ValueType >> &local_rhs, const std::shared_ptr< gko::matrix::Dense< ValueType >> &global_solution, const std::shared_ptr< gko::matrix::Csr< ValueType, IndexType >> &interface_matrix)=0
Update the values into local vector from obtained from the neighboring sub-domains using the interfac...
Definition: communicate.cpp:56
std::shared_ptr< gko::Array< IndexType * > > local_put
The array containing the number of elements that each subdomain sends from the other.
Definition: communicate.hpp:125
std::shared_ptr< gko::Array< IndexType * > > local_get
The array containing the number of elements that each subdomain gets from the other.
Definition: communicate.hpp:139