150 {
151 ErrorCode result = MB_SUCCESS;
152 int success;
153 int buff_size;
154
155 auto add_verts = [&](
Range &sent_ents) {
156
157
158
159
160 std::pair<Range::const_iterator, Range::const_iterator> set_range =
161 sent_ents.equal_range(MBENTITYSET);
162 ErrorCode result = MB_SUCCESS, tmp_result;
163 for (Range::const_iterator rit = set_range.first; rit != set_range.second;
164 ++rit) {
165 tmp_result = moab_tmp.get_entities_by_type(*rit, MBVERTEX, sent_ents);
167 }
168
169
171 std::copy(sent_ents.begin(), set_range.first, range_inserter(tmp_ents));
172 result = moab_tmp.get_adjacencies(tmp_ents, 0, false, sent_ents,
173 moab::Interface::UNION);
174 CHK_MOAB_THROW(result,
"Failed to get vertices adj to ghosted ents");
175
176 return result;
177 };
178
179 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab_tmp,
MYPCOMM_INDEX);
180 auto &procConfig = pcomm->proc_config();
181 const int MAX_BCAST_SIZE = (1 << 28);
182
183 ParallelComm::Buffer buff(ParallelComm::INITIAL_BUFF_SIZE);
184 buff.reset_ptr(sizeof(int));
185 if ((int)procConfig.proc_rank() == from_proc) {
186
187 result = add_verts(entities);
189
190 buff.reset_ptr(sizeof(int));
191 result = pcomm->pack_buffer(entities, adjacencies, tags, false, -1, &buff);
193 "Failed to compute buffer size in broadcast_entities");
194 buff.set_stored_size();
195 buff_size = buff.buff_ptr - buff.mem_ptr;
196 }
197
198 success =
199 MPI_Bcast(&buff_size, 1, MPI_INT, from_proc, procConfig.proc_comm());
200 if (MPI_SUCCESS != success) {
202 }
203
204 if (!buff_size)
205 return MB_SUCCESS;
206
207 if ((int)procConfig.proc_rank() != from_proc)
208 buff.reserve(buff_size);
209
210 size_t offset = 0;
211 while (buff_size) {
212 int sz = std::min(buff_size, MAX_BCAST_SIZE);
213 success = MPI_Bcast(buff.mem_ptr + offset, sz, MPI_UNSIGNED_CHAR, from_proc,
214 procConfig.proc_comm());
215 if (MPI_SUCCESS != success) {
217 }
218
219 offset += sz;
220 buff_size -= sz;
221 }
222
223 std::vector<std::vector<EntityHandle>> dum1a, dum1b;
224 std::vector<std::vector<int>> dum1p;
225 std::vector<EntityHandle> dum2, dum4;
226 std::vector<unsigned int> dum3;
227 buff.reset_ptr(sizeof(int));
228 if ((int)procConfig.proc_rank() == from_proc) {
229 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
230 result = pcomm->unpack_buffer(buff.buff_ptr, false, from_proc, -1, dum1a,
231 dum1b, dum1p, dum2, dum2, dum3, dum4);
232 } else {
233 result = pcomm->unpack_buffer(buff.buff_ptr, false, from_proc, -1, dum1a,
234 dum1b, dum1p, dum2, dum2, dum3, dum4);
235 }
236 CHK_MOAB_THROW(result,
"Failed to unpack buffer in broadcast_entities");
237 std::copy(dum4.begin(), dum4.end(), range_inserter(entities));
238
239 return MB_SUCCESS;
240};
#define MYPCOMM_INDEX
default communicator number PCOMM
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
#define THROW_MESSAGE(msg)
Throw MoFEM exception.