Chi-Tech
AAH_AsynComm_buildmessagestructure.cc
Go to the documentation of this file.
1#include "AAH_AsynComm.h"
2
6
7//###################################################################
8/**Builds message structure.
9 *
10 * Outgoing and incoming data needs to be sub-divided into messages
11 * each of which is smaller than the MPI eager-limit. There are
12 * three parts to this: predecessors, delayed-predecessors and successors.
13 *
14 * This method gets called by an angleset that subscribes to this
15 * sweepbuffer.*/
17{
18 const auto& spds = fluds_.GetSPDS();
19 auto& aah_fluds = dynamic_cast<AAH_FLUDS&>(fluds_);
20
21 //============================================= Predecessor locations
22 size_t num_dependencies = spds.GetLocationDependencies().size();
23
24 prelocI_message_count.resize(num_dependencies,0);
25 prelocI_message_size.resize(num_dependencies);
26 prelocI_message_blockpos.resize(num_dependencies);
28
29 for (int prelocI=0; prelocI<num_dependencies; prelocI++)
30 {
31 u_ll_int num_unknowns =
32 aah_fluds.GetPrelocIFaceDOFCount(prelocI)*num_groups_*num_angles_;
33
34 u_ll_int message_size;
35 int message_count;
36 if ((num_unknowns*8)<=EAGER_LIMIT)
37 {
38 message_count = static_cast<int>(num_angles_);
39 message_size = ceil((double)num_unknowns/(double)message_count);
40 }
41 else
42 {
43 message_count = ceil((double)num_unknowns*8/(double)(double)EAGER_LIMIT);
44 message_size = ceil((double)num_unknowns/(double)message_count);
45 }
46
47 prelocI_message_count[prelocI] = message_count;
48
49 u_ll_int pre_block_pos = 0;
50 for (int m=0; m<(message_count-1); m++)
51 {
52 prelocI_message_size[prelocI].push_back(message_size);
53 prelocI_message_blockpos[prelocI].push_back(pre_block_pos);
54 num_unknowns -= message_size;
55 pre_block_pos += message_size;
56 }
57 if (num_unknowns>0)
58 {
59 prelocI_message_blockpos[prelocI].push_back(pre_block_pos);
60 prelocI_message_size[prelocI].push_back(num_unknowns);
61 }
62
63 prelocI_message_received.emplace_back(message_count, false);
64 }//for prelocI
65
66 //============================================= Delayed Predecessor locations
67 size_t num_delayed_dependencies = spds.GetDelayedLocationDependencies().size();
68
69 delayed_prelocI_message_count.resize(num_delayed_dependencies,0);
70 delayed_prelocI_message_size.resize(num_delayed_dependencies);
71 delayed_prelocI_message_blockpos.resize(num_delayed_dependencies);
73
74 for (int prelocI=0; prelocI<num_delayed_dependencies; prelocI++)
75 {
76 u_ll_int num_unknowns =
77 aah_fluds.GetDelayedPrelocIFaceDOFCount(prelocI)*num_groups_*num_angles_;
78
79 u_ll_int message_size;
80 int message_count;
81 if ((num_unknowns*8)<=EAGER_LIMIT)
82 {
83 message_count = static_cast<int>(num_angles_);
84 message_size = ceil((double)num_unknowns/(double)message_count);
85 }
86 else
87 {
88 message_count = ceil((double)num_unknowns*8/(double)(double)EAGER_LIMIT);
89 message_size = ceil((double)num_unknowns/(double)message_count);
90 }
91
92 delayed_prelocI_message_count[prelocI] = message_count;
93
94 u_ll_int pre_block_pos = 0;
95 for (int m=0; m<(message_count-1); m++)
96 {
97 delayed_prelocI_message_size[prelocI].push_back(message_size);
98 delayed_prelocI_message_blockpos[prelocI].push_back(pre_block_pos);
99 num_unknowns -= message_size;
100 pre_block_pos += message_size;
101 }
102 if (num_unknowns>0)
103 {
104 delayed_prelocI_message_blockpos[prelocI].push_back(pre_block_pos);
105 delayed_prelocI_message_size[prelocI].push_back(num_unknowns);
106 }
107
108 delayed_prelocI_message_received.emplace_back(message_count, false);
109 }
110
111
112 //============================================= Successor locations
113 size_t num_successors = spds.GetLocationSuccessors().size();
114
115 deplocI_message_count.resize(num_successors,0);
116 deplocI_message_size.resize(num_successors);
117 deplocI_message_blockpos.resize(num_successors);
118
120
121 for (int deplocI=0; deplocI<num_successors; deplocI++)
122 {
123 u_ll_int num_unknowns =
124 aah_fluds.GetDeplocIFaceDOFCount(deplocI)*num_groups_*num_angles_;
125
126 u_ll_int message_size;
127 int message_count;
128 if ((num_unknowns*8)<=EAGER_LIMIT)
129 {
130 message_count = static_cast<int>(num_angles_);
131 message_size = ceil((double)num_unknowns/(double)message_count);
132 }
133 else
134 {
135 message_count = ceil((double)num_unknowns*8/(double)(double)EAGER_LIMIT);
136 message_size = ceil((double)num_unknowns/(double)message_count);
137 }
138
139 deplocI_message_count[deplocI] = message_count;
140
141 u_ll_int dep_block_pos = 0;
142 for (int m=0; m<(message_count-1); m++)
143 {
144 deplocI_message_size[deplocI].push_back(message_size);
145 deplocI_message_blockpos[deplocI].push_back(dep_block_pos);
146 num_unknowns -= message_size;
147 dep_block_pos += message_size;
148 }
149 if (num_unknowns>0)
150 {
151 deplocI_message_blockpos[deplocI].push_back(dep_block_pos);
152 deplocI_message_size[deplocI].push_back(num_unknowns);
153 }
154
155 deplocI_message_request.emplace_back(message_count,MPI_Request());
156 }
157
158 //================================================== All reduce to get
159 // maximum message count
160 int angset_max_message_count = 0;
161 for (size_t prelocI=0; prelocI<num_dependencies; prelocI++)
162 angset_max_message_count =
163 std::max(prelocI_message_count[prelocI], angset_max_message_count);
164
165 for (size_t prelocI=0; prelocI<num_delayed_dependencies; prelocI++)
166 angset_max_message_count =
167 std::max(delayed_prelocI_message_count[prelocI], angset_max_message_count);
168
169 for (size_t deplocI=0; deplocI<num_successors; deplocI++)
170 angset_max_message_count =
171 std::max(deplocI_message_count[deplocI], angset_max_message_count);
172
173 //Temporarily assign max_num_mess tot he local maximum
174 max_num_mess = angset_max_message_count;
175}
unsigned long long int u_ll_int
Definition: AAH_AsynComm.h:9
std::vector< std::vector< u_ll_int > > delayed_prelocI_message_blockpos
Definition: AAH_AsynComm.h:46
std::vector< std::vector< u_ll_int > > delayed_prelocI_message_size
Definition: AAH_AsynComm.h:42
std::vector< std::vector< u_ll_int > > deplocI_message_blockpos
Definition: AAH_AsynComm.h:45
std::vector< std::vector< bool > > prelocI_message_received
Definition: AAH_AsynComm.h:48
std::vector< std::vector< u_ll_int > > deplocI_message_size
Definition: AAH_AsynComm.h:41
std::vector< std::vector< u_ll_int > > prelocI_message_size
Definition: AAH_AsynComm.h:40
std::vector< std::vector< bool > > delayed_prelocI_message_received
Definition: AAH_AsynComm.h:49
std::vector< std::vector< MPI_Request > > deplocI_message_request
Definition: AAH_AsynComm.h:51
std::vector< std::vector< u_ll_int > > prelocI_message_blockpos
Definition: AAH_AsynComm.h:44
const SPDS & GetSPDS() const
Definition: FLUDS.h:31