WARPXM v1.10.0
Loading...
Searching...
No Matches
exchange.h
Go to the documentation of this file.
1#ifndef EXCHANGE_T_H
2#define EXCHANGE_T_H
3
4// STL includes
5#include <vector>
6
7// Wm includes
12
13namespace wxm
14{
15namespace dfem
16{
17namespace sync
18{
19namespace tools
20{
21
23{
24public:
26 : _link(link),
27 _from_patch_index(link.from_patch().getPatchIndex()),
28 _to_patch_index(link.to_patch().getPatchIndex()),
29 _from_element_indexes(link.from_indexes()),
30 _to_element_indexes(link.to_indexes()),
31 _num_transfer_elements(link.getNumElements()),
32 _to_rank(link.to_patch().getProcID()),
33 _from_rank(link.from_patch().getProcID())
34
35 {
36 }
37
41 const std::vector<int>& _from_element_indexes;
42 const std::vector<int>& _to_element_indexes;
46
47protected:
48};
49
50typedef std::vector<sync_link_t*> sync_links_t;
51
53{
54public:
56 {
57 }
58
59 virtual ~sync_chunk_t()
60 {
61 for (size_t child_index = 0; child_index < _children.size(); child_index++)
62 {
63 SAFE_DELETE(_children[child_index]);
64 }
65 }
66
74 virtual size_t size()
75 {
76 const int num_children = _children.size();
77 _children_offsets.resize(num_children + 1, 0);
78 for (int child_index = 0; child_index < num_children; child_index++)
79 {
80 sync_chunk_t& child = *_children[child_index];
81 _children_offsets[child_index + 1] =
82 _children_offsets[child_index] + child.size();
83 }
84 return _children_offsets.back();
85 }
86
87 // /**
88 // * @brief Used to exchange between two local patches
89 // */
90 // virtual void direct_write()
91 // {
92 // for(int child_index = 0; child_index < _children.size(); child_index++){
93 // sync_chunk_t & child = *_children[child_index];
94 // child.direct_write();
95 // }
96 // }
97
105 virtual void read(const real* from_data)
106 {
107 for (size_t child_index = 0; child_index < _children.size(); child_index++)
108 {
109 sync_chunk_t& child = *_children[child_index];
110 child.read(from_data + _children_offsets[child_index]);
111 }
112 }
113
121 virtual void write(real* to_data, size_t buf_size)
122 {
123 for (size_t child_index = 0; child_index < _children.size(); child_index++)
124 {
125 sync_chunk_t& child = *_children[child_index];
126 if (buf_size < _children_offsets[child_index])
127 {
128 std::cerr << "buffer is too small\n";
129 throw -1;
130 }
131 child.write(to_data + _children_offsets[child_index],
132 buf_size - _children_offsets[child_index]);
133 }
134 }
135
136protected:
138 std::vector<int> _children_offsets;
139
141 std::vector<sync_chunk_t*> _children;
142};
143
149{
150public:
154 const int component_index);
155
156 // /**
157 // * @brief Used to exchange between two local patches
158 // */
159 // void direct_write();
160
161 // debugging stuff
163
171 void read(const real* from_data);
172
180 void write(real* to_data, size_t buf_size);
181
189 size_t size()
190 {
192 }
193
194protected:
197
200
203
206};
207
213{
214public:
224 const int component_index);
225
226protected:
229
230private:
231};
232
238{
239public:
246 rank_exchange_t(const WmDomain& domain, int from_rank, int to_rank);
247
250
256 size_t size();
257
264 const int component_index);
265
272 void send();
273
281 void recv_init();
282
289 void recv_wait();
290
298 void send_init();
299
306 void send_wait();
307
308protected:
311
314
316 std::vector<real> _buffer_allocation;
317
320
323
326
329
332
335};
336
337typedef std::vector<rank_exchange_t*> rank_exchanges_t;
338
344{
345public:
350 patch_exchange_t(const WmUnstructuredPatchLink& link, const int tag_seed);
351
354
361 const int component_index);
362
368 size_t size();
369
376 void send();
377
385 void send_init();
386
393 void send_wait();
394
402 void recv_init();
403
410 void recv_wait();
411
412protected:
415
417 std::vector<real> _buffer_allocation;
418
421
424
429};
430
431typedef std::vector<patch_exchange_t*> patch_exchanges_t;
432} // namespace tools
433} // namespace sync
434} // namespace dfem
435} // namespace wxm
436
437#endif // EXCHANGE_T_H
Definition: wmdomain.h:35
Provides an abstract interface for message based communication between different processes.
Definition: wxmsgbase.h:22
The component_exchange_t class is used to exchange a component between two sets of patches.
Definition: exchange.h:213
const sync_links_t & _sync_links
List of links defining exchange.
Definition: exchange.h:228
component_exchange_t(const sync_links_t &sync_links, wxm::dfem::variable::distributed_variable_t &variable, const int component_index)
Constructor for an exchange defining a group of patch exchanges for a single component.
The component_patch_exchange_t class is used to exchange information between two patches.
Definition: exchange.h:149
component_patch_exchange_t(const sync_link_t &link, wxm::dfem::variable::distributed_variable_t &variable, const int component_index)
Constructor.
size_t size()
Size of patch exchange chunk.
Definition: exchange.h:189
int _component_index
Index of component in variable.
Definition: exchange.h:202
void read(const real *from_data)
Read patch exchange data from pointer.
const sync_link_t & _link
Link associated with transfer.
Definition: exchange.h:205
void write(real *to_data, size_t buf_size)
Write patch exchange chunk to pointer.
wxm::dfem::variable::distributed_variable_t & _variable
Host variable of component.
Definition: exchange.h:196
size_t _element_size
Number of reals in each element.
Definition: exchange.h:199
The patch_exchange_t class is used to exchange sets of components existing between two patches.
Definition: exchange.h:344
int _msg_tag
Unique tag for msg messages.
Definition: exchange.h:420
void add_component(wxm::dfem::variable::distributed_variable_t &variable, const int component_index)
Adds a variable's component to the exchange.
patch_exchange_t(const WmUnstructuredPatchLink &link, const int tag_seed)
Constructor.
const WxMsgBase & _msg
Reference to msg object.
Definition: exchange.h:423
WxMsgStatus recv_status
Msg status object used to know when recv has completed.
Definition: exchange.h:428
sync_link_t _sync_link
Link assoicated with inter-patch connection.
Definition: exchange.h:414
std::vector< real > _buffer_allocation
Buffer allocation used for storing data for sync operation.
Definition: exchange.h:417
void recv_init()
Receives data from the to_patch.
void send_init()
Sends data from the from_patch.
void send()
Sends data from the from_patch to the to_patch.
void send_wait()
Waits for the data to be transmitted from the to_patch to the from_patch.
void recv_wait()
Waits for the data to be transmitted from the from_patch to the to_patch.
size_t size()
Used to define the size of the range.
WxMsgStatus send_status
Msg status object used to know when send has completed.
Definition: exchange.h:426
The rank_exchange_t class is used to exchange sets of components existing between sets of patches on ...
Definition: exchange.h:238
WxMsgStatus send_status
Msg status object used to know when send has completed.
Definition: exchange.h:334
void recv_wait()
Waits for the data to be transmitted from the from_rank to the to_rank.
int _msg_tag
Unique tag for msg messages.
Definition: exchange.h:325
const WxMsgBase & _msg
Reference to msg object.
Definition: exchange.h:328
void send_wait()
Waits for the data to be transmitted from the to_rank to the from_rank.
int _from_rank
Rank to recv data from.
Definition: exchange.h:322
size_t size()
Used to define the size of the range.
std::vector< real > _buffer_allocation
Buffer allocation used for storing data for sync operation.
Definition: exchange.h:316
const WmDomain & _domain
Reference to domain object.
Definition: exchange.h:313
void send()
Sends data from the from_rank to the to_rank.
void recv_init()
Receives data from the to_rank.
int _to_rank
Rank to send data to.
Definition: exchange.h:319
rank_exchange_t(const WmDomain &domain, int from_rank, int to_rank)
Construct the rank exchange given a from_rank and a to_rank (defines links)
void send_init()
Sends data from the from_rank.
void add_component(wxm::dfem::variable::distributed_variable_t &variable, const int component_index)
Adds a variable's component to the exchange.
WxMsgStatus recv_status
Msg status object used to know when recv has completed.
Definition: exchange.h:331
sync_links_t _sync_links
List of links assoicated with inter-rank connections.
Definition: exchange.h:310
Definition: exchange.h:53
std::vector< sync_chunk_t * > _children
Children associated with this chunk.
Definition: exchange.h:141
sync_chunk_t()
Definition: exchange.h:55
virtual void read(const real *from_data)
Read patch exchange data from pointer.
Definition: exchange.h:105
virtual ~sync_chunk_t()
Definition: exchange.h:59
std::vector< int > _children_offsets
List of offsets into a synchronization buffer.
Definition: exchange.h:138
virtual void write(real *to_data, size_t buf_size)
Write patch exchange chunk to pointer.
Definition: exchange.h:121
virtual size_t size()
Size of patch exchange chunk.
Definition: exchange.h:74
Definition: distributed_variable.h:101
std::vector< rank_exchange_t * > rank_exchanges_t
Definition: exchange.h:337
std::vector< sync_link_t * > sync_links_t
Definition: exchange.h:50
std::vector< patch_exchange_t * > patch_exchanges_t
Definition: exchange.h:431
Base namespace for everything not included in the global namespace.
Definition: field_source.h:8
Provides a means for derived messengers to return implimentation specific message status flags and da...
Definition: wxmsgtmpl.h:19
#define real
Definition: wmoclunstructuredreconstruction.h:11
#define SAFE_DELETE(ptr)
Definition: wmudgfunctions.h:18