Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
parallel_mesh.hpp
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// Copyright (C) 2024 - 2026 by the Vulpes authors.
4// This file is part of Vulpes.
5//
6// Vulpes is free software; you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Vulpes is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with Vulpes. If not, see <http://www.gnu.org/licenses/>.
18//
19// ----------------------------------------------------------------------
20
21// Author: Francesco Rosnati <francesco.rosnati@polimi.it>
22// Author: Matteo Caldana <matteo.caldana@polimi.it>
23// Author: Pedro Peixoto <ppeixoto@usp.br>
24
25#ifndef VULPES_GEOMETRY_PARALLEL_MESH_HPP_
26#define VULPES_GEOMETRY_PARALLEL_MESH_HPP_
27
28#include <parmetis.h>
29
30#include <algorithm>
31#include <iostream>
32#include <memory>
33#include <string>
34#include <utility>
35#include <vector>
36
37#include <boost/unordered/unordered_flat_map.hpp>
38#include <boost/unordered/unordered_flat_set.hpp>
39
44
45namespace vulpes {
46namespace geometry {
47
73template <typename Mesh>
74class ParallelMesh : public Mesh {
75 public:
79 using index_t = typename Mesh::index_t;
83 using SetType = boost::unordered_flat_set<index_t>;
87 using GlobalToLocalMap = boost::unordered_flat_map<index_t, index_t>;
88
92 inline static constexpr auto self_dim = Mesh::self_dim;
93
97 using MeshGenerator = std::function<Mesh()>;
98
102 ParallelMesh() = default;
103
111 explicit ParallelMesh(const MeshGenerator& generator) : Mesh() {
112 std::unique_ptr<Mesh> mesh_ptr;
113 if (mpi::root()) {
114 mesh_ptr = std::make_unique<Mesh>(generator());
115 }
116 initFromRank0(std::move(mesh_ptr));
117 }
118
129 template <class Archive>
130 void serialize(Archive& ar, const unsigned int) {
131 ar& static_cast<Mesh&>(*this);
132 ar & m_weak_dual;
136 ar & m_own_enty_size;
138 ar & m_edgecut;
140 ar & m_all_own_size;
141 ar & m_all_ghost_size;
142 }
143
152 friend bool operator==(const ParallelMesh& lhs, const ParallelMesh& rhs) {
153 return (static_cast<const Mesh&>(lhs) == static_cast<const Mesh&>(rhs)) &&
154 (lhs.m_weak_dual == rhs.m_weak_dual) &&
158 (lhs.m_own_enty_size == rhs.m_own_enty_size) &&
160 (lhs.m_edgecut == rhs.m_edgecut) &&
163 (lhs.m_all_own_size == rhs.m_all_own_size) &&
165 }
166
180 void initFromRank0(std::unique_ptr<Mesh> rank0_mesh) {
181 if (mpi::root()) {
182 assert(mpi::size() < rank0_mesh->numCells());
183 }
184 std::cout << "Initializing parallel mesh" << std::endl;
185 m_rank0_mesh = std::move(rank0_mesh);
187 std::cout << "partitionWithParmetis" << std::endl;
188 std::vector<SCOTCH_Num> partition_parmetis = partitionWithParmetis();
189 std::vector<index_t> partition;
190 if constexpr (std::is_same_v<index_t, SCOTCH_Num>) {
191 partition = std::move(partition_parmetis);
192 } else {
193 partition.assign(partition_parmetis.begin(), partition_parmetis.end());
194 }
195 std::cout << "buildGhostCells" << std::endl;
196 buildGhostCells(partition);
197 std::cout << "buildLocalCellToEntityMaps" << std::endl;
199 std::cout << "buildLocalRenumbering" << std::endl;
201 std::cout << "buildLocalEntityToCellMaps" << std::endl;
203 std::cout << "buildLocalToLocalMaps" << std::endl;
206 }
207
212 constexpr index_t nLocEntity(std::size_t dim) const {
213 return m_own_enty_size[dim];
214 }
215
219 constexpr index_t nOwnedCells() const { return nLocEntity(self_dim); }
220
225 constexpr index_t nGhostEntity(std::size_t dim) const {
226 return m_ghost_enty_size[dim];
227 }
228
233 constexpr index_t nEntity(std::size_t dim) const {
234 assert(dim < m_global_entity_size.size());
235 return m_global_entity_size[dim];
236 }
237
241 constexpr static inline bool parallel() { return true; }
242
246 constexpr const auto& localToGlobal(std::size_t d) const {
247 return m_local_numbering[d];
248 }
249
252 constexpr const auto& globalToLocal(std::size_t d) const {
253 return m_global_numbering[d];
254 }
255
262 const auto& getRank0Mesh() const { return *m_rank0_mesh; }
263
264 const auto& getDualGlobalMap() const { return m_dual_graph_glob; }
265 const auto& getCellToFacetGlobalMap() const { return m_cell_to_facet_glob; }
266 const auto& getCellToVtxGlobalMap() const { return m_cell_to_vtx_glob; }
267 const auto& getFacetToCellGlobalMap() const { return m_facet_to_cell_glob; }
268 const auto& getFacetToVtxGlobalMap() const { return m_facet_to_vtx_glob; }
269 const auto& getVtxToCellGlobalMap() const { return m_vtx_to_cell_glob; }
270 const auto& getEdgeToVtxGlobalMap() const { return m_edge_to_vtx_glob; }
271 const auto& getCellToEdgeGlobalMap() const { return m_cell_to_edge_glob; }
272 const auto& getEdgeToCellGlobalMap() const { return m_edge_to_cell_glob; }
273
282 template <std::size_t req_dim>
283 constexpr auto& getEntityToCellGlobalMap() const {
284 if constexpr (req_dim == 0) {
285 return this->getVtxToCellGlobalMap();
286 } else if constexpr (self_dim == 2 && req_dim == 1) {
287 return this->getFacetToCellGlobalMap();
288 } else if constexpr (self_dim == 3 && req_dim == 1) {
289 return this->getEdgeToCellGlobalMap();
290 } else if constexpr (self_dim == 3 && req_dim == 2) {
291 return this->getFacetToCellGlobalMap();
292 } else {
293 static_assert(false, "getEntityToCellGlobalMap: unsupported dimension");
294 }
295 }
296
297 protected:
310 std::vector<SCOTCH_Num> partitionWithParmetis();
322 void buildGhostCells(std::vector<index_t>& part);
334 void reconstructPartitioningAndScatterDual(std::vector<index_t>& part);
374 void initializeMeshTags();
382 void sendMeshTags(
383 const std::vector<index_t>& vertex_numbering, int destination);
387 void receiveMeshTags();
412 void buildWeakDual();
442 std::unique_ptr<Mesh> m_rank0_mesh;
443
448
452 std::array<index_t, Mesh::self_dim + 1> m_global_entity_size;
453
459 std::array<std::vector<index_t>, Mesh::self_dim + 1> m_local_numbering;
465 std::array<GlobalToLocalMap, Mesh::self_dim + 1> m_global_numbering;
466
470 std::array<index_t, Mesh::self_dim + 1> m_own_enty_size = {0};
475 std::array<index_t, Mesh::self_dim + 1> m_ghost_enty_size = {0};
476
480 SCOTCH_Num m_edgecut = -1;
481
488 std::vector<std::vector<index_t>> m_all_own_and_ghost_cell_id;
492 std::vector<index_t> m_all_own_size;
496 std::vector<index_t> m_all_ghost_size;
497
498 typename Mesh::DualMap m_dual_graph_glob;
499 typename Mesh::CellToFacetMap m_cell_to_facet_glob;
500 typename Mesh::CellToVtxMap m_cell_to_vtx_glob;
501 typename Mesh::FacetToCellMap m_facet_to_cell_glob;
502 typename Mesh::FacetToVtxMap m_facet_to_vtx_glob;
503 typename Mesh::VtxToCellMap m_vtx_to_cell_glob;
504 typename Mesh::EdgeToVtxMap m_edge_to_vtx_glob;
505 typename Mesh::CellToEdgeMap m_cell_to_edge_glob;
506 typename Mesh::EdgeToCellMap m_edge_to_cell_glob;
507};
508
509template <typename Mesh>
511 using real_t = float;
512 const auto rank = mpi::rank();
513 const auto size = mpi::size();
514 // how many vertices on each proc
515 std::vector<SCOTCH_Num> vtxdist(size + 1);
516 // crs map in Metis format
517 std::vector<SCOTCH_Num> xadj;
518 std::vector<SCOTCH_Num> adjncy;
519
520 if (rank == 0) {
521 const auto& dual = m_rank0_mesh->getDualMap();
522
523 // how many vertices on each proc
524 vtxdist[0] = 0;
525 for (int i = 0; i < size; ++i) {
526 vtxdist[i + 1] =
527 vtxdist[i] + dual.size() / size + (i < (dual.size() % size));
528 }
529 assert(vtxdist.back() == dual.size());
530
531 // build local crs map for others
532 for (int p = 1; p < size; ++p) {
533 xadj.resize(vtxdist[p + 1] - vtxdist[p] + 1);
534 const std::size_t adjncy_size =
535 dual.indices()[vtxdist[p + 1]] - dual.indices()[vtxdist[p]];
536 const auto offset = dual.indices()[vtxdist[p]];
537 for (std::size_t j = 0; j < xadj.size(); ++j) {
538 xadj[j] = dual.indices()[j + vtxdist[p]] - offset;
539 }
540 mpi::send(xadj, p);
541 mpi::send(adjncy_size, p);
542 mpi::send(&dual.data()[offset], adjncy_size, p);
543 }
544
545 // build local crs map for self
546 xadj.assign(
547 dual.indices().begin(), dual.indices().begin() + vtxdist[1] + 1);
548 adjncy.assign(
549 dual.data().begin(), dual.data().begin() + dual.indices()[vtxdist[1]]);
550 } else {
551 mpi::recv(xadj, 0);
552 adjncy.resize(mpi::recv<std::size_t>(0));
553 mpi::recv(adjncy.data(), static_cast<int32_t>(adjncy.size()), 0);
554 }
555 mpi::bcast(vtxdist, 0);
556
557 // ParMETIS parameters
558 SCOTCH_Num ncon = 1;
559 SCOTCH_Num wgtflag = 0;
560 SCOTCH_Num numflag = 0;
561 SCOTCH_Num nparts = size;
562 real_t ubvec = 1.05;
563 const SCOTCH_Num random_seed = 0;
564 SCOTCH_Num options[3] = {1, 0, random_seed};
565 std::vector<real_t> tpwgts(nparts);
566 for (int i = 0; i < size; ++i) {
567 tpwgts[i] = 1. / static_cast<double>(nparts);
568 }
569
570 // result buffer
571 std::vector<SCOTCH_Num> part(vtxdist[rank + 1] - vtxdist[rank]);
572
573 std::cout << "Partition the graph;" << std::endl;
574 // Partition the graph
575 auto comm = MPI_COMM_WORLD;
576 ParMETIS_V3_PartKway(
577 vtxdist.data(), xadj.data(), adjncy.data(), nullptr, nullptr, &wgtflag,
578 &numflag, &ncon, &nparts, tpwgts.data(), &ubvec, options, &m_edgecut,
579 part.data(), &comm);
580 return part;
581}
582
583template <typename Mesh>
585 std::vector<index_t>& part) {
586 const auto size = mpi::size();
587 std::vector<index_t> all_parts;
588 if (mpi::root()) {
589 const auto& dual = m_rank0_mesh->getDualMap();
590 std::cout << "Partitioning completed. Edge cuts: " << m_edgecut
591 << std::endl;
592 // std::cout << "rank 0 | part: " << part << std::endl;
593 all_parts = part;
594 for (int p = 1; p < size; ++p) {
595 mpi::recv(part, p);
596 // std::cout << "rank " << p << " | part: " << part << std::endl;
597 all_parts.insert(all_parts.end(), part.begin(), part.end());
598 }
599
600 // we re-order the partition to minimize the bandwidth
601 // of the processors block
602 // In practice if two partitions are connected they should
603 // belong also to procs that are close together
604 Eigen::MatrixXi dense_proc_adj = Eigen::MatrixXi::Zero(size, size);
605 for (index_t cell_id = 0; cell_id < dual.size(); ++cell_id) {
606 const auto src_cell_proc = all_parts[cell_id];
607 for (index_t neigh_cell_id : dual[cell_id]) {
608 const auto dst_cell_proc = all_parts[neigh_cell_id];
609 dense_proc_adj(src_cell_proc, dst_cell_proc) = 1;
610 }
611 }
613 uncomp_proc_adj.resize(size);
614 for (Eigen::Index i = 0; i < dense_proc_adj.rows(); ++i) {
615 for (Eigen::Index j = 0; j < dense_proc_adj.cols(); ++j) {
616 if (dense_proc_adj(i, j)) {
617 uncomp_proc_adj[i].push_back(j);
618 }
619 }
620 }
621 const auto proc_adj = uncomp_proc_adj.template compress<index_t>();
622 const auto [perm, perm_inv] =
624 for (std::size_t i = 0; i < all_parts.size(); ++i) {
625 all_parts[i] = perm[all_parts[i]];
626 }
627
628 for (std::size_t cell_id = 0; cell_id < all_parts.size(); ++cell_id) {
629 m_all_own_and_ghost_cell_id[all_parts[cell_id]].push_back(cell_id);
630 }
631
632 for (int p = 0; p < size; ++p) {
634 }
635
636 // send dual map of owned cells
637 for (int p = 1; p < size; ++p) {
639 mpi::send(dual.slice(m_all_own_and_ghost_cell_id[p]), p);
640 }
642 this->getDualMap() = dual.slice(m_all_own_and_ghost_cell_id[0]);
643 } else {
644 mpi::send(part, 0);
646 mpi::recv(this->getDualMap(), 0);
647 }
648}
649
650template <typename Mesh>
652 const auto size = mpi::size();
653 SetType ghost_cell_set(size);
654 for (index_t loc_cid = 0; loc_cid < m_weak_dual.size(); ++loc_cid) {
655 for (auto glob_neigh_id : m_weak_dual[loc_cid]) {
656 auto it = std::lower_bound(
658 m_local_numbering[self_dim].end(), glob_neigh_id);
659 if ((it == m_local_numbering[self_dim].end()) || (*it != glob_neigh_id)) {
660 ghost_cell_set.insert(glob_neigh_id);
661 }
662 }
663 }
665 m_ghost_enty_size[self_dim] = ghost_cell_set.size();
667 m_local_numbering[self_dim].end(), ghost_cell_set.begin(),
668 ghost_cell_set.end());
669}
670
671template <typename Mesh>
673 const auto size = mpi::size();
674 if (mpi::root()) {
675 // receive ghost from procs
679 for (int p = 1; p < size; ++p) {
683 mpi::recv(
685 m_all_ghost_size[p], p);
686 }
687 } else {
689 mpi::send(
691 m_ghost_enty_size[self_dim], 0, MPI_COMM_WORLD);
692 }
693}
694
695template <typename Mesh>
696void ParallelMesh<Mesh>::buildGhostCells(std::vector<index_t>& part) {
697 const auto size = mpi::size();
698 m_all_own_and_ghost_cell_id.resize(size);
699 m_all_own_size.resize(size);
700 m_all_ghost_size.resize(size);
701 // send partitions to root and compute ghost
702 // reconstruct partitioning and send dual map owning slice
704
705 // In the ghost cells we want also the weakly connected cells
706 // that is the cells that share also only a vertex
707 // Indeed, we need this information to compute the sparsity pattern
711}
712
713template <typename Mesh>
715 const auto size = mpi::size();
716 // build and send local maps
717 if (mpi::root()) {
718 for (int p = 1; p < size; ++p) {
719 mpi::send(
720 m_rank0_mesh->getDualMap().slice(m_all_own_and_ghost_cell_id[p]), p);
721 const auto cell_to_vtx_loc =
722 m_rank0_mesh->getCellToVtxMap().slice(m_all_own_and_ghost_cell_id[p]);
723 mpi::send(cell_to_vtx_loc, p);
724 const auto cell_to_facet_loc = m_rank0_mesh->getCellToFacetMap().slice(
726 mpi::send(cell_to_facet_loc, p);
727 if constexpr (self_dim == 3) {
728 const auto cell_to_edge_loc = m_rank0_mesh->getCellToEdgeMap().slice(
730 mpi::send(cell_to_edge_loc, p);
731 }
732 }
733 // build for self
734 this->getDualMap() =
735 m_rank0_mesh->getDualMap().slice(m_all_own_and_ghost_cell_id[0]);
736 this->getCellToVtxMap() =
737 m_rank0_mesh->getCellToVtxMap().slice(m_all_own_and_ghost_cell_id[0]);
738 this->getCellToFacetMap() =
739 m_rank0_mesh->getCellToFacetMap().slice(m_all_own_and_ghost_cell_id[0]);
740 if constexpr (self_dim == 3) {
741 this->getCellToEdgeMap() = m_rank0_mesh->getCellToEdgeMap().slice(
743 }
744 } else {
745 mpi::recv(this->getDualMap(), 0);
746 mpi::recv(this->getCellToVtxMap(), 0);
747 mpi::recv(this->getCellToFacetMap(), 0);
748 if constexpr (self_dim == 3) {
749 mpi::recv(this->getCellToEdgeMap(), 0);
750 }
751 }
752}
753
754template <typename Mesh>
756 const auto size = mpi::size();
757 // scatter the cell to vtx map
758 if (mpi::root()) {
759 for (int p = 0; p < size; ++p) {
760 const auto cell_to_vtx_loc =
761 m_rank0_mesh->getCellToVtxMap().slice(m_all_own_and_ghost_cell_id[p]);
762 if (p > 0) {
763 mpi::send(cell_to_vtx_loc, p);
764 } else {
765 this->getCellToVtxMap() = cell_to_vtx_loc;
766 }
767 }
768 } else {
769 mpi::recv(this->getCellToVtxMap(), 0);
770 }
771 // find unique local vertices
772 const auto& vtx_loc = this->getCellToVtxMap().data();
773 SetType need_vtxs_set(vtx_loc.begin(), vtx_loc.end());
774 std::vector<index_t> need_vtxs(need_vtxs_set.begin(), need_vtxs_set.end());
775 // send to root the unique vertices and scatter the vtx to cell map
776 if (mpi::root()) {
777 std::vector<index_t> need_vtxs_tmp;
778 for (int p = 1; p < size; ++p) {
779 mpi::recv(need_vtxs_tmp, p);
780 mpi::send(m_rank0_mesh->getVtxToCellMap().slice(need_vtxs_tmp), p);
781 }
782 this->getVtxToCellMap() = m_rank0_mesh->getVtxToCellMap().slice(need_vtxs);
783 } else {
784 mpi::send(need_vtxs, 0);
785 mpi::recv(this->getVtxToCellMap(), 0);
786 }
787 // invert vtx mapping
788 boost::unordered_flat_map<index_t, index_t> vtx_glob_to_loc;
789 for (std::size_t i = 0; i < need_vtxs.size(); ++i) {
790 vtx_glob_to_loc[need_vtxs[i]] = i;
791 }
792 // compute weak dual
793 const auto n_loc_cell = this->getCellToVtxMap().size();
795 weak_dual_uncompressed.resize(n_loc_cell);
796 for (index_t loc_cell_id = 0; loc_cell_id < n_loc_cell; ++loc_cell_id) {
797 SetType weak_neigh;
798 for (auto glob_vtx_id : this->getCellToVtxMap()[loc_cell_id]) {
799 const auto loc_vtx_id = vtx_glob_to_loc[glob_vtx_id];
800 for (auto glob_neigh_cell : this->getVtxToCellMap()[loc_vtx_id]) {
801 weak_neigh.insert(glob_neigh_cell);
802 }
803 }
804 weak_dual_uncompressed[loc_cell_id].assign(
805 weak_neigh.begin(), weak_neigh.end());
806 }
807 m_weak_dual = weak_dual_uncompressed.template compress<index_t>();
808}
809
810template <typename Mesh>
812 SetType vtx_idxs, facet_idxs, edge_idxs;
813
814 // compute the owning part
815 const auto n_owned_cells = m_own_enty_size[self_dim];
816 for (index_t cell_id = 0; cell_id < n_owned_cells; ++cell_id) {
817 for (const auto vtx_id : this->getCellToVtxMap()[cell_id]) {
818 vtx_idxs.insert(vtx_id);
819 }
820 for (const auto facet_id : this->getCellToFacetMap()[cell_id]) {
821 facet_idxs.insert(facet_id);
822 }
823 if constexpr (self_dim == 3) {
824 for (const auto edge_id : this->getCellToEdgeMap()[cell_id]) {
825 edge_idxs.insert(edge_id);
826 }
827 }
828 }
829 // build local to global as vector
830 m_local_numbering[0].assign(vtx_idxs.begin(), vtx_idxs.end());
831 m_local_numbering[self_dim - 1].assign(facet_idxs.begin(), facet_idxs.end());
832 if constexpr (self_dim == 3) {
833 m_local_numbering[self_dim - 2].assign(edge_idxs.begin(), edge_idxs.end());
834 }
835 for (std::size_t d = 0; d < self_dim; ++d) {
836 m_own_enty_size[d] = m_local_numbering[d].size();
837 }
838 // compute the non-owning part
839 const auto n_ghost_cells = m_ghost_enty_size[self_dim];
840 const auto n_total_cells = n_ghost_cells + n_owned_cells;
841 for (index_t cell_id = n_owned_cells; cell_id < n_total_cells; ++cell_id) {
842 for (const auto vtx_id : this->getCellToVtxMap()[cell_id]) {
843 const auto [it, inserted] = vtx_idxs.insert(vtx_id);
844 if (inserted) {
845 m_local_numbering[0].push_back(vtx_id);
846 }
847 }
848 for (const auto facet_id : this->getCellToFacetMap()[cell_id]) {
849 const auto [it, inserted] = facet_idxs.insert(facet_id);
850 if (inserted) {
851 m_local_numbering[self_dim - 1].push_back(facet_id);
852 }
853 }
854 if constexpr (self_dim == 3) {
855 for (const auto edge_id : this->getCellToEdgeMap()[cell_id]) {
856 const auto [it, inserted] = edge_idxs.insert(edge_id);
857 if (inserted) {
858 m_local_numbering[self_dim - 2].push_back(edge_id);
859 }
860 }
861 }
862 }
863 for (std::size_t d = 0; d < self_dim; ++d) {
865 }
866
867 // build global to local by inversion
868 for (std::size_t d = 0; d < self_dim + 1; ++d) {
869 const auto& local_map = m_local_numbering[d];
870 for (std::size_t i = 0; i < local_map.size(); ++i) {
871 m_global_numbering[d][local_map[i]] = i;
872 }
873 }
874}
875
876template <typename Mesh>
878 const auto initialize_dim = [this](std::size_t dim) {
879 auto& local_tag_table = this->getMeshTags().tags[dim];
880 local_tag_table.clear();
881 // rank 0 identifies genuine entity tags.
882 std::vector<std::string> tag_names;
883 if (mpi::root()) {
884 const auto& global_tag_table = m_rank0_mesh->getMeshTags().tags[dim];
885 for (const auto& [tag_name, tag_values] : global_tag_table) {
886 if (tag_values.size() ==
887 static_cast<std::size_t>(m_global_entity_size[dim])) {
888 tag_names.push_back(tag_name);
889 }
890 }
891 // rnsure identical communication order on every rank.
892 std::sort(tag_names.begin(), tag_names.end());
893 }
894 // broadcast the number of tags.
895 std::size_t n_tags = tag_names.size();
896 mpi::bcast(n_tags, 0);
897 if (!mpi::root()) {
898 tag_names.resize(n_tags);
899 }
900 // broadcast tag names.
901 for (auto& tag_name : tag_names) {
902 mpi::bcast(tag_name, 0);
903 }
904 // extract tag values according to local-to-global numbering.
905 const auto build_local_tag =
906 [](const std::vector<index_t>& global_tag,
907 const std::vector<index_t>& local_to_global) {
908 std::vector<index_t> local_tag;
909 local_tag.reserve(local_to_global.size());
910 for (const auto global_id : local_to_global) {
911 local_tag.push_back(global_tag[global_id]);
912 }
913 return local_tag;
914 };
915 if (mpi::root()) {
916 const auto& global_tag_table = m_rank0_mesh->getMeshTags().tags[dim];
917 // construct rank 0's local tags.
918 for (const auto& tag_name : tag_names) {
919 local_tag_table[tag_name] = build_local_tag(
920 global_tag_table.at(tag_name), m_local_numbering[dim]);
921 }
922 } else {
923 // register tag names; values are received later.
924 for (const auto& tag_name : tag_names) {
925 local_tag_table[tag_name] = {};
926 }
927 }
928 };
929 initialize_dim(Mesh::VtxEnty);
930 initialize_dim(Mesh::CellEnty);
931}
932
933template <typename Mesh>
935 const std::vector<index_t>& vertex_numbering, int destination) {
936 // construct locally ordered tag values.
937 const auto build_local_tag = [](const std::vector<index_t>& global_tag,
938 const std::vector<index_t>& local_to_global) {
939 std::vector<index_t> local_tag;
940 local_tag.reserve(local_to_global.size());
941 for (const auto global_id : local_to_global) {
942 local_tag.push_back(global_tag[global_id]);
943 }
944 return local_tag;
945 };
946 const auto send_dim = [this, destination, &build_local_tag](
947 std::size_t dim,
948 const std::vector<index_t>& numbering) {
949 const auto& global_tag_table = m_rank0_mesh->getMeshTags().tags[dim];
950 const auto& local_tag_table = this->getMeshTags().tags[dim];
951 // recover the initialized tag names.
952 std::vector<std::string> tag_names;
953 tag_names.reserve(local_tag_table.size());
954 for (const auto& [tag_name, tag_values] : local_tag_table) {
955 tag_names.push_back(tag_name);
956 }
957 std::sort(tag_names.begin(), tag_names.end());
958 // extract and send each tag.
959 for (const auto& tag_name : tag_names) {
960 const auto local_tag =
961 build_local_tag(global_tag_table.at(tag_name), numbering);
962 mpi::send(local_tag, destination);
963 }
964 };
965 // vertex tags: reuse numbering received from the destination rank.
966 send_dim(Mesh::VtxEnty, vertex_numbering);
967 // cell tags: numbering already available on rank 0.
968 send_dim(Mesh::CellEnty, m_all_own_and_ghost_cell_id[destination]);
969}
970
971template <typename Mesh>
973 const auto receive_dim = [this](std::size_t dim) {
974 auto& local_tag_table = this->getMeshTags().tags[dim];
975 // recover the initialized tag names
976 std::vector<std::string> tag_names;
977 tag_names.reserve(local_tag_table.size());
978 for (const auto& [tag_name, tag_values] : local_tag_table) {
979 tag_names.push_back(tag_name);
980 }
981 // match the order used by sendMeshTags()
982 std::sort(tag_names.begin(), tag_names.end());
983 // receive and store locally ordered tag values
984 for (const auto& tag_name : tag_names) {
985 std::vector<index_t> local_tag;
986 mpi::recv(local_tag, 0);
987 local_tag_table[tag_name] = std::move(local_tag);
988 }
989 };
990
991 receive_dim(Mesh::VtxEnty);
992 receive_dim(Mesh::CellEnty);
993}
994
995template <typename Mesh>
997 const auto size = mpi::size();
998
999 // mesh tags initialization
1001
1002 // build local maps in root and distribute them
1003 if (mpi::root()) {
1004 {
1005 std::array<std::vector<index_t>, self_dim> local_numbering;
1006 for (int p = 1; p < size; ++p) {
1007 // recv local to global numbering
1008 for (std::size_t d = 0; d < self_dim; ++d) {
1009 mpi::recv(local_numbering[d], p);
1010 }
1011 // disttribute local vertex numbering for mesh tag distribution
1012 sendMeshTags(local_numbering[0], p);
1013
1014 // build and send vtxs and local maps (F2C F2V V2C [E2C])
1015 const auto vtx_loc =
1016 vutils::slice(m_rank0_mesh->getVertexes(), local_numbering[0]);
1017 mpi::send(vtx_loc, p);
1018 const auto facet_to_cell_loc = vutils::slice(
1019 m_rank0_mesh->getFacetToCellMap(), local_numbering[self_dim - 1]);
1020 mpi::send(facet_to_cell_loc, p);
1021 const auto facet_to_vtx_loc = m_rank0_mesh->getFacetToVtxMap().slice(
1022 local_numbering[self_dim - 1]);
1023 mpi::send(facet_to_vtx_loc, p);
1024 mpi::send(m_rank0_mesh->getVtxToCellMap().slice(local_numbering[0]), p);
1025 if constexpr (self_dim == 3) {
1026 const auto edge_to_cell_loc = m_rank0_mesh->getEdgeToCellMap().slice(
1027 local_numbering[self_dim - 2]);
1028 mpi::send(edge_to_cell_loc, p);
1029
1030 const auto edge_to_vtx_loc = vutils::slice(
1031 m_rank0_mesh->getEdgeToVtxMap(), local_numbering[self_dim - 2]);
1032 mpi::send(edge_to_vtx_loc, p);
1033 }
1034 }
1035 }
1036 // build for self
1037 this->getVertexes() =
1038 vutils::slice(m_rank0_mesh->getVertexes(), m_local_numbering[0]);
1039 this->getFacetToCellMap() = vutils::slice(
1040 m_rank0_mesh->getFacetToCellMap(), m_local_numbering[self_dim - 1]);
1041 this->getFacetToVtxMap() =
1042 m_rank0_mesh->getFacetToVtxMap().slice(m_local_numbering[self_dim - 1]);
1043 this->getVtxToCellMap() =
1044 m_rank0_mesh->getVtxToCellMap().slice(m_local_numbering[0]);
1045 if constexpr (self_dim == 3) {
1046 this->getEdgeToCellMap() = m_rank0_mesh->getEdgeToCellMap().slice(
1048 this->getEdgeToVtxMap() = vutils::slice(
1049 m_rank0_mesh->getEdgeToVtxMap(), m_local_numbering[self_dim - 2]);
1050 }
1051 } else {
1052 // send local numbering to root
1053 for (std::size_t d = 0; d < self_dim; ++d) {
1055 }
1056 // receive the send from sendMeshTags() above
1058
1059 // recv vertices and local maps (F2C F2V V2C [E2C])
1060 mpi::recv(this->getVertexes(), 0);
1061 mpi::recv(this->getFacetToCellMap(), 0);
1062 mpi::recv(this->getFacetToVtxMap(), 0);
1063 mpi::recv(this->getVtxToCellMap(), 0);
1064 if constexpr (self_dim == 3) {
1065 mpi::recv(this->getEdgeToCellMap(), 0);
1066 mpi::recv(this->getEdgeToVtxMap(), 0);
1067 }
1068 }
1070}
1071
1072template <typename Mesh>
1074 // in the maps we may have references to cells that do not belong to
1075 // the proc that owns that map.
1076 // `owned_table` has size of # of global cells, which scales badly
1077 // (linear with the number of proc). However this should not be a
1078 // large issue since it is a temporary object that is allocated
1079 // in a staggered way by the processors, since they enter in this
1080 // function just after rank 0 has finished computing the local map
1081 std::vector<bool> owned_table(m_global_entity_size.back(), false);
1082 for (const auto global_cell_id : m_local_numbering[self_dim]) {
1083 owned_table[global_cell_id] = true;
1084 }
1085 // Dual
1086 assert(
1087 this->getDualMap().size() ==
1089 for (auto& glob_cell_id : this->getDualMap().data()) {
1090 if (!owned_table[glob_cell_id]) {
1091 glob_cell_id = -1;
1092 }
1093 }
1094 this->getDualMap().remove(-1);
1095 // F2C
1096 const auto n_loc_faces = this->getFacetToCellMap().size();
1097 for (std::size_t loc_face_id = 0; loc_face_id < n_loc_faces; ++loc_face_id) {
1098 for (auto& glob_cell_id : this->getFacetToCellMap()[loc_face_id]) {
1099 if (glob_cell_id == -1) {
1100 continue;
1101 }
1102 if (!owned_table[glob_cell_id]) {
1103 glob_cell_id = -1;
1104 }
1105 }
1106 }
1107 // V2C
1108 for (auto& glob_cell_id : this->getVtxToCellMap().data()) {
1109 if (!owned_table[glob_cell_id]) {
1110 glob_cell_id = -1;
1111 }
1112 }
1113 this->getVtxToCellMap().remove(-1);
1114 // E2C
1115 if constexpr (self_dim == 3) {
1116 for (auto& glob_cell_id : this->getEdgeToCellMap().data()) {
1117 if (!owned_table[glob_cell_id]) {
1118 glob_cell_id = -1;
1119 }
1120 }
1121 this->getEdgeToCellMap().remove(-1);
1122 }
1123}
1124
1125template <typename Mesh>
1127 if (mpi::root()) {
1128 for (std::size_t d = 0; d < self_dim + 1; ++d) {
1129 m_global_entity_size[d] = m_rank0_mesh->nEntity(d);
1130 }
1131 }
1133}
1134
1135template <typename Mesh>
1137 m_dual_graph_glob = this->m_dual_graph;
1138 m_cell_to_facet_glob = this->m_cell_to_facet;
1139 m_cell_to_vtx_glob = this->m_cell_to_vtx;
1140 m_facet_to_cell_glob = this->m_facet_to_cell;
1141 m_facet_to_vtx_glob = this->m_facet_to_vtx;
1142 m_vtx_to_cell_glob = this->m_vtx_to_cell;
1143
1144 for (auto& cid : this->m_dual_graph.data()) {
1145 cid = m_global_numbering[self_dim].at(cid);
1146 }
1147 for (auto& fid : this->m_cell_to_facet.data()) {
1148 fid = m_global_numbering[self_dim - 1].at(fid);
1149 }
1150 for (auto& vid : this->m_cell_to_vtx.data()) {
1151 vid = m_global_numbering[0].at(vid);
1152 }
1153 for (auto& cid0cid1 : this->m_facet_to_cell) {
1154 if (cid0cid1[0] != static_cast<index_t>(-1)) {
1155 cid0cid1[0] = m_global_numbering[self_dim].at(cid0cid1[0]);
1156 }
1157 if (cid0cid1[1] != static_cast<index_t>(-1)) {
1158 cid0cid1[1] = m_global_numbering[self_dim].at(cid0cid1[1]);
1159 }
1160 }
1161 for (auto& vid : this->m_facet_to_vtx.data()) {
1162 vid = m_global_numbering[0].at(vid);
1163 }
1164 for (auto& cid : this->m_vtx_to_cell.data()) {
1165 cid = m_global_numbering[self_dim].at(cid);
1166 }
1167
1168 if constexpr (self_dim == 3) {
1169 m_edge_to_vtx_glob = this->m_edge_to_vtx;
1170 m_cell_to_edge_glob = this->m_cell_to_edge;
1171 m_edge_to_cell_glob = this->m_edge_to_cell;
1172
1173 for (auto& v1v2 : this->m_edge_to_vtx) {
1174 v1v2[0] = m_global_numbering[0].at(v1v2[0]);
1175 v1v2[1] = m_global_numbering[0].at(v1v2[1]);
1176 }
1177 for (auto& eid : this->m_cell_to_edge.data()) {
1178 eid = m_global_numbering[1].at(eid);
1179 }
1180 for (auto& cid : this->m_edge_to_cell.data()) {
1181 cid = m_global_numbering[self_dim].at(cid);
1182 }
1183 }
1184}
1185
1186template <typename Mesh>
1188 // Check if the serial mesh (rank 0) is periodic.
1189 // Returns immediately for non-periodic meshes, preserving existing behaviour.
1190 // Use int (not bool) because getMpiType<bool> is not defined.
1191 int is_periodic = 0;
1192 if (mpi::root() && m_rank0_mesh) {
1193 const auto& md = m_rank0_mesh->getMetadata();
1194 is_periodic =
1195 ((md.doubles.count("XPeriod") > 0) && (md.doubles.count("YPeriod") > 0))
1196 ? 1
1197 : 0;
1198 }
1199 mpi::bcast(is_periodic, 0);
1200 if (!is_periodic) {
1201 return;
1202 }
1203
1204 // Collect all required data on rank 0, then broadcast.
1205 std::vector<double> x_period, y_period, ghost_x, ghost_y;
1206 std::vector<index_t> global_n_vtx_vec;
1207 std::vector<index_t> serial_cdata, serial_cindices;
1208
1209 if (mpi::root()) {
1210 const auto& md = m_rank0_mesh->getMetadata();
1211 x_period = md.doubles.at("XPeriod");
1212 y_period = md.doubles.at("YPeriod");
1213 ghost_x = md.doubles.at("GhostVertices_x");
1214 ghost_y = md.doubles.at("GhostVertices_y");
1215 global_n_vtx_vec = {
1216 static_cast<index_t>(md.ints.at("NumVertices").front())};
1217
1218 // closePeriodicTopology stores connectivity in cell tags;
1219 // some VTU round-trips may put it in md.ints - check both.
1220 const auto& ct = m_rank0_mesh->getMeshTags().tags[Mesh::CellEnty];
1221 if (ct.count("CellToVtxMap_with_ghosts_data")) {
1222 serial_cdata.assign(
1223 ct.at("CellToVtxMap_with_ghosts_data").begin(),
1224 ct.at("CellToVtxMap_with_ghosts_data").end());
1225 serial_cindices.assign(
1226 ct.at("CellToVtxMap_with_ghosts_indices").begin(),
1227 ct.at("CellToVtxMap_with_ghosts_indices").end());
1228 } else {
1229 serial_cdata = md.ints.at("CellToVtxMap_with_ghosts_data");
1230 serial_cindices = md.ints.at("CellToVtxMap_with_ghosts_indices");
1231 }
1232 }
1233
1234 mpi::bcast(x_period, 0);
1235 mpi::bcast(y_period, 0);
1236 mpi::bcast(ghost_x, 0);
1237 mpi::bcast(ghost_y, 0);
1238 mpi::bcast(global_n_vtx_vec, 0);
1239 mpi::bcast(serial_cdata, 0);
1240 mpi::bcast(serial_cindices, 0);
1241
1242 const index_t global_n_vtx = global_n_vtx_vec[0];
1243 // All vertices in the local mesh (owned + MPI-ghost) are REAL vertices
1244 // (global IDs 0..global_n_vtx-1). Periodic ghost vertices (virtual images
1245 // used for cell geometry) are appended after local_n_vtx.
1246 const index_t local_n_vtx = static_cast<index_t>(m_local_numbering[0].size());
1247
1248 // Rebuild CellToVtxMap_with_ghosts with local vertex IDs for this rank.
1249 const index_t n_local_cells =
1250 static_cast<index_t>(m_local_numbering[self_dim].size());
1251 std::vector<index_t> local_cdata;
1252 std::vector<index_t> local_cindices;
1253 local_cindices.reserve(n_local_cells + 1);
1254 local_cindices.push_back(0);
1255
1256 for (index_t loc_cid = 0; loc_cid < n_local_cells; ++loc_cid) {
1257 const index_t glob_cid = m_local_numbering[self_dim][loc_cid];
1258 const index_t start = serial_cindices[glob_cid];
1259 const index_t end = serial_cindices[glob_cid + 1];
1260 for (index_t k = start; k < end; ++k) {
1261 const index_t vtx = serial_cdata[k];
1262 if (vtx < global_n_vtx) {
1263 // Real vertex: translate global to local ID.
1264 local_cdata.push_back(m_global_numbering[0].at(vtx));
1265 } else {
1266 // Periodic ghost vertex (virtual copy, not an actual mesh vertex):
1267 // offset past all local real vertices so getCellVertexesPeriodic
1268 // looks it up in GhostVertices_x/y.
1269 local_cdata.push_back(local_n_vtx + (vtx - global_n_vtx));
1270 }
1271 }
1272 local_cindices.push_back(static_cast<index_t>(local_cdata.size()));
1273 }
1274
1275 // Store in the local mesh metadata. getCellVertexesPeriodic prefers
1276 // md.ints over cell tags for connectivity, so we write there.
1277 auto& md = this->getMetadata();
1278 md.doubles["XPeriod"] = std::move(x_period);
1279 md.doubles["YPeriod"] = std::move(y_period);
1280 md.doubles["GhostVertices_x"] = std::move(ghost_x);
1281 md.doubles["GhostVertices_y"] = std::move(ghost_y);
1282 md.ints["NumVertices"] = {local_n_vtx};
1283 md.ints["CellToVtxMap_with_ghosts_data"] = std::move(local_cdata);
1284 md.ints["CellToVtxMap_with_ghosts_indices"] = std::move(local_cindices);
1285}
1286
1287} // namespace geometry
1288} // namespace vulpes
1289
1290#endif // VULPES_GEOMETRY_PARALLEL_MESH_HPP_
A class that behaves like a vector of vectors, providing automatic row range checking.
Definition crs_map.hpp:758
constexpr void resize(std::size_t new_size)
Resizes the map to contain the specified number of SmallVector objects.
Definition crs_map.hpp:807
constexpr void push_back(const SmallVector< DataType, N > &value)
Appends a copy of a SmallVector to the map.
Definition crs_map.hpp:830
Definition crs_map.hpp:72
constexpr const auto & localToGlobal(std::size_t d) const
Local to global map for geometric entities of a certain dim.
Definition parallel_mesh.hpp:246
std::vector< index_t > m_all_ghost_size
number of ghost cells for each proc, only rank 0 knows it
Definition parallel_mesh.hpp:496
static constexpr auto self_dim
The dimension of the mesh (e.g., 2 for a 2D mesh, 3 for a 3D mesh).
Definition parallel_mesh.hpp:92
Mesh::EdgeToCellMap m_edge_to_cell_glob
Definition parallel_mesh.hpp:506
void sendMeshTags(const std::vector< index_t > &vertex_numbering, int destination)
Builds and sends local mesh tags from rank 0 to another rank.
Definition parallel_mesh.hpp:934
void reconstructPartitioningAndScatterDual(std::vector< index_t > &part)
Reconstructs the full mesh partitioning on rank 0 and scatters the (strong) dual graph.
Definition parallel_mesh.hpp:584
Mesh::EdgeToVtxMap m_edge_to_vtx_glob
Definition parallel_mesh.hpp:504
Mesh::FacetToVtxMap m_facet_to_vtx_glob
Definition parallel_mesh.hpp:502
std::array< index_t, Mesh::self_dim+1 > m_global_entity_size
global number of vertices, edges, faces, cells
Definition parallel_mesh.hpp:452
void initFromRank0(std::unique_ptr< Mesh > rank0_mesh)
Parallelizes a mesh that has already been built on rank 0.
Definition parallel_mesh.hpp:180
constexpr index_t nOwnedCells() const
Number of cells owned by this proc.
Definition parallel_mesh.hpp:219
const auto & getFacetToCellGlobalMap() const
Definition parallel_mesh.hpp:267
boost::unordered_flat_map< index_t, index_t > GlobalToLocalMap
Alias for an unordered map from global indices to local indices.
Definition parallel_mesh.hpp:87
const auto & getRank0Mesh() const
Returns a constant reference to the original mesh on rank 0, valid only for root.
Definition parallel_mesh.hpp:262
void buildLocalCellToEntityMaps()
Builds and distributes local cell-to-entity maps.
Definition parallel_mesh.hpp:714
Mesh::DualMap m_dual_graph_glob
Definition parallel_mesh.hpp:498
const auto & getCellToVtxGlobalMap() const
Definition parallel_mesh.hpp:266
void collectGhostCellsInRoot()
Gathers ghost cell information on the root process.
Definition parallel_mesh.hpp:672
Mesh::FacetToCellMap m_facet_to_cell_glob
Definition parallel_mesh.hpp:501
std::array< index_t, Mesh::self_dim+1 > m_ghost_enty_size
number of ghost [vtxs, edge, facet, cell] owned by this process, they are the last ones in the local ...
Definition parallel_mesh.hpp:475
const auto & getFacetToVtxGlobalMap() const
Definition parallel_mesh.hpp:268
void initializeMeshTags()
Initializes vertex and cell mesh tags.
Definition parallel_mesh.hpp:877
std::vector< std::vector< index_t > > m_all_own_and_ghost_cell_id
global mesh partitioning, only rank 0 knows it
Definition parallel_mesh.hpp:488
void buildWeakDual()
Builds the weak dual graph of the local mesh partition.
Definition parallel_mesh.hpp:755
void buildLocalToLocalMaps()
Converts global entity numbering in the maps to local numbering.
Definition parallel_mesh.hpp:1136
const auto & getCellToEdgeGlobalMap() const
Definition parallel_mesh.hpp:271
const auto & getEdgeToVtxGlobalMap() const
Definition parallel_mesh.hpp:270
void buildGhostCells(std::vector< index_t > &part)
Builds the ghost cells for the mesh.
Definition parallel_mesh.hpp:696
std::array< index_t, Mesh::self_dim+1 > m_own_enty_size
number of [vtxs, edge, facet, cell] owned by this process
Definition parallel_mesh.hpp:470
SCOTCH_Num m_edgecut
number of edge cuts ParMetis makes
Definition parallel_mesh.hpp:480
Mesh::CellToFacetMap m_cell_to_facet_glob
Definition parallel_mesh.hpp:499
constexpr index_t nLocEntity(std::size_t dim) const
Number of geometric entities of a certain dim (see enum Entity) owned by this proc.
Definition parallel_mesh.hpp:212
ParallelMesh()=default
Default constructor.
static constexpr bool parallel()
Returns true if the mesh is parallel, which it is.
Definition parallel_mesh.hpp:241
std::unique_ptr< Mesh > m_rank0_mesh
A unique pointer to the original mesh.
Definition parallel_mesh.hpp:442
void buildLocalEntityToCellMaps()
Builds and distributes local entity-to-cell maps.
Definition parallel_mesh.hpp:996
std::vector< SCOTCH_Num > partitionWithParmetis()
Partitions the mesh's dual graph using ParMETIS.
Definition parallel_mesh.hpp:510
typename Mesh::index_t index_t
Alias for the index type of the base mesh class.
Definition parallel_mesh.hpp:79
void receiveMeshTags()
Receives local vertex and cell tags from rank 0.
Definition parallel_mesh.hpp:972
std::array< GlobalToLocalMap, Mesh::self_dim+1 > m_global_numbering
global to local numbering of vertices, edges, faces, cells
Definition parallel_mesh.hpp:465
std::vector< index_t > m_all_own_size
number of owned cells for each proc, only rank 0 knows it
Definition parallel_mesh.hpp:492
void serialize(Archive &ar, const unsigned int)
Serializes the parallel mesh data.
Definition parallel_mesh.hpp:130
boost::unordered_flat_set< index_t > SetType
Alias for an unordered set of indices, optimized for performance.
Definition parallel_mesh.hpp:83
ParallelMesh(const MeshGenerator &generator)
Constructor that generates a mesh on rank 0 and then parallelizes it.
Definition parallel_mesh.hpp:111
constexpr index_t nGhostEntity(std::size_t dim) const
Number of ghost geometric entities of a certain dim (see enum Entity) for this proc.
Definition parallel_mesh.hpp:225
datastructure::CrsMap< index_t, index_t > m_weak_dual
cell to cell mapping of cells that share at least a vertex
Definition parallel_mesh.hpp:447
void removeNotOwnedFromLocalEntityToCellMaps()
Removes references to non-owned cells from the local entity-to-cell maps.
Definition parallel_mesh.hpp:1073
const auto & getVtxToCellGlobalMap() const
Definition parallel_mesh.hpp:269
friend bool operator==(const ParallelMesh &lhs, const ParallelMesh &rhs)
Compares two ParallelMesh objects for equality.
Definition parallel_mesh.hpp:152
const auto & getCellToFacetGlobalMap() const
Definition parallel_mesh.hpp:265
std::function< Mesh()> MeshGenerator
A function object that generates a serial mesh.
Definition parallel_mesh.hpp:97
Mesh::CellToVtxMap m_cell_to_vtx_glob
Definition parallel_mesh.hpp:500
Mesh::VtxToCellMap m_vtx_to_cell_glob
Definition parallel_mesh.hpp:503
const auto & getEdgeToCellGlobalMap() const
Definition parallel_mesh.hpp:272
void buildGhostCellsFromWeakDual()
Determines ghost cells based on the weak dual graph.
Definition parallel_mesh.hpp:651
void buildLocalRenumbering()
Establishes local-to-global and global-to-local numbering for all entities.
Definition parallel_mesh.hpp:811
constexpr index_t nEntity(std::size_t dim) const
Global number of geometric entities of a certain dim (see enum Entity).
Definition parallel_mesh.hpp:233
void distributePeriodicMetadata()
If the serial mesh had periodic topology, broadcasts the periodic ghost-vertex metadata from rank 0 a...
Definition parallel_mesh.hpp:1187
constexpr auto & getEntityToCellGlobalMap() const
A template function that returns the global entity-to-cell map for a given dimension.
Definition parallel_mesh.hpp:283
constexpr const auto & globalToLocal(std::size_t d) const
Global to local map for geometric entities of a certain dim.
Definition parallel_mesh.hpp:252
void buildGlobalEntitySize()
Gathers and broadcasts the total number of global entities.
Definition parallel_mesh.hpp:1126
const auto & getDualGlobalMap() const
Definition parallel_mesh.hpp:264
std::array< std::vector< index_t >, Mesh::self_dim+1 > m_local_numbering
local to global numbering of vertices, edges, faces, cells
Definition parallel_mesh.hpp:459
Mesh::CellToEdgeMap m_cell_to_edge_glob
Definition parallel_mesh.hpp:505
Permutation< T > computeReverseCuthillMckeeOrdering(const datastructure::CrsMap< T, T > &sparsity_pattern, bool reversed)
Returns the permutation array that orders a sparse CSR matrix in Reverse-Cuthill McKee ordering.
Definition numbering.hpp:89
Definition abs_agg_model.cpp:40
void recv(T *data, int count, int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
Receive count contiguous values of type T from a source rank.
Definition mpi_wrappers.hpp:311
static int rank()
Return the MPI rank in MPI_COMM_WORLD.
Definition mpi_wrappers.hpp:116
static int size()
Return the size of MPI_COMM_WORLD.
Definition mpi_wrappers.hpp:124
static bool root()
Return true if the rank in MPI_COMM_WORLD is zero.
Definition mpi_wrappers.hpp:132
void send(const T *data, int count, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
Send count contiguous values of type T to a destination rank.
Definition mpi_wrappers.hpp:149
void bcast(T *data, int count, int root, MPI_Comm communicator=MPI_COMM_WORLD)
Broadcast count contiguous values of type T from root.
Definition mpi_wrappers.hpp:495
std::vector< T > slice(const std::vector< T > &source, const std::vector< IndexType > &indices)
Build a new vector by selecting elements of source at the given indices.
Definition vvutils.hpp:117
Definition cell_manager.hpp:38
#define PROFILE_INTERVAL(func)
Time a single execution of func under the label #func using Profiler::startInterval()/stopInterval().
Definition profiler.hpp:56