21 #ifndef THUNDEREGG_SCHUR_INTERFACE_H
22 #define THUNDEREGG_SCHUR_INTERFACE_H
82 std::shared_ptr<const PatchIfaceInfo<D>>
piinfo;
91 return std::const_pointer_cast<PatchIfaceInfo<D>>(
piinfo);
137 NbrType nbr_type = piinfo->pinfo.getNbrType(s);
141 auto info = piinfo->getFineIfaceInfo(s);
142 if (info->id ==
id) {
146 if (info->fine_ids[o.getIndex()] ==
id) {
153 auto info = piinfo->getCoarseIfaceInfo(s);
154 if (info->id ==
id) {
170 for (
auto patch : ifs.
patches) {
179 int size = (int)
patches.size();
182 writer << patch.side;
183 writer << patch.type;
184 writer << *patch.piinfo;
195 for (
int i = 0; i < size; i++) {
198 auto piinfo = std::make_shared<PatchIfaceInfo<D>>();
202 patches.emplace_back(s, type, piinfo);
217 static void InsertPatchToInterface(
218 std::map<
int, std::map<
int, std::shared_ptr<
Interface<D>>>>& rank_id_iface_map,
224 std::shared_ptr<Interface<D>>& iface_ptr = rank_id_iface_map[rank][
id];
225 if (iface_ptr ==
nullptr) {
228 iface_ptr->insert(s, piinfo);
239 static void InsertInterfaceWithNormalNbr(
240 std::map<
int, std::map<
int, std::shared_ptr<Interface<D>>>>& rank_id_iface_map,
241 std::set<int>& incoming_procs,
242 std::shared_ptr<
const PatchIfaceInfo<D>> piinfo,
246 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
247 auto info = piinfo->getNormalIfaceInfo(s);
248 auto nbr_info = piinfo->pinfo.getNormalNbrInfo(s);
249 InsertPatchToInterface(rank_id_iface_map, info->rank, info->id, s, piinfo);
250 if (info->rank == piinfo->pinfo.rank && nbr_info.rank != piinfo->pinfo.rank) {
251 incoming_procs.insert(nbr_info.rank);
263 static void InsertInterfacesWithFineNbr(
264 std::map<
int, std::map<
int, std::shared_ptr<Interface<D>>>>& rank_id_iface_map,
265 std::set<int>& incoming_procs,
266 std::shared_ptr<
const PatchIfaceInfo<D>> piinfo,
269 auto info = piinfo->getFineIfaceInfo(s);
271 InsertPatchToInterface(rank_id_iface_map, info->rank, info->id, s, piinfo);
273 for (
size_t i = 0; i < Orthant<D - 1>::num_orthants; i++) {
274 InsertPatchToInterface(rank_id_iface_map, info->fine_ranks[i], info->fine_ids[i], s, piinfo);
276 if (info->fine_ranks[i] != piinfo->pinfo.rank) {
277 incoming_procs.insert(info->fine_ranks[i]);
290 static void InsertInterfacesWithCoarseNbr(
291 std::map<
int, std::map<
int, std::shared_ptr<Interface<D>>>>& rank_id_iface_map,
292 std::set<int>& incoming_procs,
293 std::shared_ptr<
const PatchIfaceInfo<D>> piinfo,
296 auto info = piinfo->getCoarseIfaceInfo(s);
298 InsertPatchToInterface(rank_id_iface_map, info->rank, info->id, s, piinfo);
299 InsertPatchToInterface(rank_id_iface_map, info->coarse_rank, info->coarse_id, s, piinfo);
301 if (info->coarse_rank != piinfo->pinfo.rank) {
302 incoming_procs.insert(info->coarse_rank);
319 std::map<
int, std::map<
int, std::shared_ptr<
Interface<D>>>>& rank_id_iface_map,
323 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
324 rank_id_iface_map.clear();
325 std::set<int> incoming_procs;
326 for (
auto piinfo : piinfos) {
328 if (piinfo->pinfo.hasNbr(s)) {
329 switch (piinfo->pinfo.getNbrType(s)) {
331 InsertInterfaceWithNormalNbr(rank_id_iface_map, incoming_procs, piinfo, s);
334 InsertInterfacesWithFineNbr(rank_id_iface_map, incoming_procs, piinfo, s);
337 InsertInterfacesWithCoarseNbr(rank_id_iface_map, incoming_procs, piinfo, s);
346 std::deque<std::vector<char>> buffers;
347 std::vector<MPI_Request> send_requests;
348 for (
auto& p : rank_id_iface_map) {
352 for (
auto q : p.second) {
353 auto& iface = q.second;
354 size += iface->serialize(
nullptr);
356 buffers.emplace_back(size);
358 for (
auto q : p.second) {
359 auto& iface = q.second;
363 MPI_Isend(buffers.back().data(), size, MPI_BYTE, dest, 0, MPI_COMM_WORLD, &request);
364 send_requests.push_back(request);
368 std::map<int, std::shared_ptr<PatchIfaceInfo<D>>> id_to_off_proc_piinfo_map;
370 MPI_Barrier(MPI_COMM_WORLD);
372 size_t num_incoming = incoming_procs.size();
373 for (
size_t i = 0; i < num_incoming; i++) {
375 MPI_Probe(MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
377 MPI_Get_count(&status, MPI_BYTE, &size);
378 std::vector<char> buffer(size);
381 buffer.data(), size, MPI_BYTE, status.MPI_SOURCE, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
384 while (reader.
getPos() < size) {
387 for (
auto& patch : ifs.patches) {
388 auto& ptr = id_to_off_proc_piinfo_map[patch.piinfo->pinfo.id];
389 if (ptr ==
nullptr) {
391 ptr = std::const_pointer_cast<PatchIfaceInfo<D>>(patch.piinfo);
396 rank_id_iface_map.at(rank).at(ifs.id)->
merge(ifs);
398 off_proc_piinfos.clear();
399 for (
auto pair : id_to_off_proc_piinfo_map) {
400 off_proc_piinfos.push_back(pair.second);
404 MPI_Waitall((
int)send_requests.size(), &send_requests[0], MPI_STATUSES_IGNORE);
407 extern template class Interface<2>;
408 extern template class Interface<3>;