![]() |
Vulpes
0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
|
This class wraps a serial mesh class and adds attributes and methods for parallelization. More...
#include <parallel_mesh.hpp>
Public Types | |
| using | index_t = typename Mesh::index_t |
| Alias for the index type of the base mesh class. | |
| using | SetType = boost::unordered_flat_set<index_t> |
| Alias for an unordered set of indices, optimized for performance. | |
| using | GlobalToLocalMap = boost::unordered_flat_map<index_t, index_t> |
| Alias for an unordered map from global indices to local indices. | |
| using | MeshGenerator = std::function<Mesh()> |
| A function object that generates a serial mesh. | |
Public Member Functions | |
| ParallelMesh ()=default | |
| Default constructor. | |
| ParallelMesh (const MeshGenerator &generator) | |
| Constructor that generates a mesh on rank 0 and then parallelizes it. | |
| template<class Archive> | |
| void | serialize (Archive &ar, const unsigned int) |
| Serializes the parallel mesh data. | |
| void | initFromRank0 (std::unique_ptr< Mesh > rank0_mesh) |
| Parallelizes a mesh that has already been built on rank 0. | |
| constexpr index_t | nLocEntity (std::size_t dim) const |
| Number of geometric entities of a certain dim (see enum Entity) owned by this proc. | |
| constexpr index_t | nOwnedCells () const |
| Number of cells owned by this proc. | |
| constexpr index_t | nGhostEntity (std::size_t dim) const |
| Number of ghost geometric entities of a certain dim (see enum
Entity) for this proc. | |
| constexpr index_t | nEntity (std::size_t dim) const |
| Global number of geometric entities of a certain dim (see enum
Entity). | |
| constexpr const auto & | localToGlobal (std::size_t d) const |
| Local to global map for geometric entities of a certain dim. | |
| constexpr const auto & | globalToLocal (std::size_t d) const |
| Global to local map for geometric entities of a certain dim. | |
| const auto & | getRank0Mesh () const |
| Returns a constant reference to the original mesh on rank 0, valid only for root. | |
| const auto & | getDualGlobalMap () const |
| const auto & | getCellToFacetGlobalMap () const |
| const auto & | getCellToVtxGlobalMap () const |
| const auto & | getFacetToCellGlobalMap () const |
| const auto & | getFacetToVtxGlobalMap () const |
| const auto & | getVtxToCellGlobalMap () const |
| const auto & | getEdgeToVtxGlobalMap () const |
| const auto & | getCellToEdgeGlobalMap () const |
| const auto & | getEdgeToCellGlobalMap () const |
| template<std::size_t req_dim> | |
| constexpr auto & | getEntityToCellGlobalMap () const |
| A template function that returns the global entity-to-cell map for a given dimension. | |
Static Public Member Functions | |
| static constexpr bool | parallel () |
| Returns true if the mesh is parallel, which it is. | |
Static Public Attributes | |
| static constexpr auto | self_dim = Mesh::self_dim |
| The dimension of the mesh (e.g., 2 for a 2D mesh, 3 for a 3D mesh). | |
Protected Member Functions | |
| std::vector< SCOTCH_Num > | partitionWithParmetis () |
| Partitions the mesh's dual graph using ParMETIS. | |
| void | buildGhostCells (std::vector< index_t > &part) |
| Builds the ghost cells for the mesh. | |
| void | reconstructPartitioningAndScatterDual (std::vector< index_t > &part) |
| Reconstructs the full mesh partitioning on rank 0 and scatters the (strong) dual graph. | |
| void | buildGhostCellsFromWeakDual () |
| Determines ghost cells based on the weak dual graph. | |
| void | collectGhostCellsInRoot () |
| Gathers ghost cell information on the root process. | |
| void | buildLocalCellToEntityMaps () |
| Builds and distributes local cell-to-entity maps. | |
| void | buildLocalRenumbering () |
| Establishes local-to-global and global-to-local numbering for all entities. | |
| void | initializeMeshTags () |
| Initializes vertex and cell mesh tags. | |
| void | sendMeshTags (const std::vector< index_t > &vertex_numbering, int destination) |
| Builds and sends local mesh tags from rank 0 to another rank. | |
| void | receiveMeshTags () |
| Receives local vertex and cell tags from rank 0. | |
| void | buildLocalEntityToCellMaps () |
| Builds and distributes local entity-to-cell maps. | |
| void | buildGlobalEntitySize () |
| Gathers and broadcasts the total number of global entities. | |
| void | buildWeakDual () |
| Builds the weak dual graph of the local mesh partition. | |
| void | buildLocalToLocalMaps () |
| Converts global entity numbering in the maps to local numbering. | |
| void | distributePeriodicMetadata () |
| If the serial mesh had periodic topology, broadcasts the periodic ghost-vertex metadata from rank 0 and rebuilds it with local vertex IDs so that Cell2D::getCellVertexesPeriodic works correctly on every rank. | |
| void | removeNotOwnedFromLocalEntityToCellMaps () |
| Removes references to non-owned cells from the local entity-to-cell maps. | |
Protected Attributes | |
| std::unique_ptr< Mesh > | m_rank0_mesh |
| A unique pointer to the original mesh. | |
| datastructure::CrsMap< index_t, index_t > | m_weak_dual |
| cell to cell mapping of cells that share at least a vertex | |
| std::array< index_t, Mesh::self_dim+1 > | m_global_entity_size |
| global number of vertices, edges, faces, cells | |
| std::array< std::vector< index_t >, Mesh::self_dim+1 > | m_local_numbering |
| local to global numbering of vertices, edges, faces, cells | |
| std::array< GlobalToLocalMap, Mesh::self_dim+1 > | m_global_numbering |
| global to local numbering of vertices, edges, faces, cells | |
| std::array< index_t, Mesh::self_dim+1 > | m_own_enty_size = {0} |
| number of [vtxs, edge, facet, cell] owned by this process | |
| std::array< index_t, Mesh::self_dim+1 > | m_ghost_enty_size = {0} |
| number of ghost [vtxs, edge, facet, cell] owned by this process, they are the last ones in the local numbering | |
| SCOTCH_Num | m_edgecut = -1 |
| number of edge cuts ParMetis makes | |
| std::vector< std::vector< index_t > > | m_all_own_and_ghost_cell_id |
| global mesh partitioning, only rank 0 knows it | |
| std::vector< index_t > | m_all_own_size |
| number of owned cells for each proc, only rank 0 knows it | |
| std::vector< index_t > | m_all_ghost_size |
| number of ghost cells for each proc, only rank 0 knows it | |
| Mesh::DualMap | m_dual_graph_glob |
| Mesh::CellToFacetMap | m_cell_to_facet_glob |
| Mesh::CellToVtxMap | m_cell_to_vtx_glob |
| Mesh::FacetToCellMap | m_facet_to_cell_glob |
| Mesh::FacetToVtxMap | m_facet_to_vtx_glob |
| Mesh::VtxToCellMap | m_vtx_to_cell_glob |
| Mesh::EdgeToVtxMap | m_edge_to_vtx_glob |
| Mesh::CellToEdgeMap | m_cell_to_edge_glob |
| Mesh::EdgeToCellMap | m_edge_to_cell_glob |
Friends | |
| bool | operator== (const ParallelMesh &lhs, const ParallelMesh &rhs) |
| Compares two ParallelMesh objects for equality. | |
This class wraps a serial mesh class and adds attributes and methods for parallelization.
It enables a mesh, initially created and owned by a single process (rank 0), to be distributed among multiple processes for parallel computation. The parallelization process involves partitioning the mesh and creating local copies for each process, including "ghost" cells that are adjacent to the owned cells but belong to other processes.
Key features:
| using vulpes::geometry::ParallelMesh< Mesh >::GlobalToLocalMap = boost::unordered_flat_map<index_t, index_t> |
Alias for an unordered map from global indices to local indices.
| using vulpes::geometry::ParallelMesh< Mesh >::index_t = typename Mesh::index_t |
Alias for the index type of the base mesh class.
| using vulpes::geometry::ParallelMesh< Mesh >::MeshGenerator = std::function<Mesh()> |
A function object that generates a serial mesh.
| using vulpes::geometry::ParallelMesh< Mesh >::SetType = boost::unordered_flat_set<index_t> |
Alias for an unordered set of indices, optimized for performance.
|
default |
Default constructor.
|
inlineexplicit |
Constructor that generates a mesh on rank 0 and then parallelizes it.
| generator | A function that returns a Mesh object. This function is called only on rank 0. |
|
protected |
Builds the ghost cells for the mesh.
It builds a "weak dual graph" (which includes cells that are connected by at least one vertex, not just a face) to correctly identify all ghost cells that might be needed for computations by each proc. It collects this information on the root process.
| part | A vector representing the cell partition for the current process. |
|
protected |
Determines ghost cells based on the weak dual graph.
One of the steps of buildGhostCells. It iterates through the weak dual graph to find neighboring cells that are not owned by the current process. These non-owned neighbors are added to the list of ghost cells.
|
protected |
Gathers and broadcasts the total number of global entities.
This method has rank 0 determine the total number of vertices, edges, faces, and cells in the global mesh and broadcasts this information to all other processes.
|
protected |
Builds and distributes local cell-to-entity maps.
This method creates local copies of the various cell-to-entity maps (CellToVtxMap, CellToFacetMap, etc.). Rank 0 slices the global maps based on the owned and ghost cells for each process and then sends these local maps to the appropriate processes.
|
protected |
Builds and distributes local entity-to-cell maps.
This method does the inverse of buildLocalCellToEntityMaps. It creates and distributes local versions of maps like VtxToCellMap, FacetToCellMap, etc.
|
protected |
Establishes local-to-global and global-to-local numbering for all entities.
It assigns a unique local index to each vertex, edge, face, and cell on the current process and maps it to its global index. This allows for efficient lookups between local and global numbering schemes.
|
protected |
Converts global entity numbering in the maps to local numbering.
This method uses the m_global_numbering map to convert all global indices within the local mesh's connectivity maps (e.g., m_cell_to_vtx) to their corresponding local indices. This makes the maps consistent with the local numbering scheme.
|
protected |
Builds the weak dual graph of the local mesh partition.
A weak dual graph connects cells that share at least one vertex (unlike a standard dual graph which connects cells that share a face). This is needed to identify all potential ghost cells that might be required by a process, even if they aren't directly adjacent along a face.
|
protected |
Gathers ghost cell information on the root process.
Each process sends its list of ghost cells to rank 0, which collects and stores this global information.
|
protected |
If the serial mesh had periodic topology, broadcasts the periodic ghost-vertex metadata from rank 0 and rebuilds it with local vertex IDs so that Cell2D::getCellVertexesPeriodic works correctly on every rank.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineconstexpr |
A template function that returns the global entity-to-cell map for a given dimension.
| req_dim | The requested dimension (0 for vertex, 1 for edge, 2 for face). |
|
inline |
|
inline |
|
inline |
Returns a constant reference to the original mesh on rank 0, valid only for root.
|
inline |
|
inlineconstexpr |
Global to local map for geometric entities of a certain dim.
|
inline |
Parallelizes a mesh that has already been built on rank 0.
This is the core method for distributing the mesh. It takes a unique pointer to a Mesh object (which is only valid on rank 0) and partitions it using ParMETIS. It then distributes the partitioned data to all processes, builds the ghost cells (which are neighbors of the owned cells but belong to other processes), and constructs the local-to-global and global-to-local maps for all entities (vertices, edges, faces, and cells).
| rank0_mesh | A unique pointer to the mesh owned by rank 0. The ownership is moved to this class. |
|
protected |
Initializes vertex and cell mesh tags.
Broadcasts tag names and builds rank 0's local tags. Must be called collectively by all ranks.
|
inlineconstexpr |
Local to global map for geometric entities of a certain dim.
|
inlineconstexpr |
Global number of geometric entities of a certain dim (see enum Entity).
|
inlineconstexpr |
Number of ghost geometric entities of a certain dim (see enum Entity) for this proc.
|
inlineconstexpr |
Number of geometric entities of a certain dim (see enum Entity) owned by this proc.
|
inlineconstexpr |
Number of cells owned by this proc.
|
inlinestaticconstexpr |
Returns true if the mesh is parallel, which it is.
|
protected |
Partitions the mesh's dual graph using ParMETIS.
This method uses the ParMETIS library to partition the dual graph of the mesh, where each node represents a cell. It distributes the dual graph data to all processes and calls ParMETIS_V3_PartKway to perform the partitioning. Each process receives its portion of the partitioning result, which indicates which cells it should own.
|
protected |
Receives local vertex and cell tags from rank 0.
|
protected |
Reconstructs the full mesh partitioning on rank 0 and scatters the (strong) dual graph.
Rank 0 collects the partition results from all other processes, reconstructs the global partitioning, and reorders it to minimize communication overhead. It then slices the global dual graph based on the new partitioning and scatters the relevant parts to each process.
| part | A vector of partition assignments for the local cells. |
|
protected |
Removes references to non-owned cells from the local entity-to-cell maps.
This method "cleans up" the local entity-to-cell maps by removing any references to cells that are not part of the process's owned or ghost cell set.
|
protected |
Builds and sends local mesh tags from rank 0 to another rank.
| vertex_numbering | Local-to-global vertex numbering of the destination. |
| destination | Destination MPI rank. |
|
inline |
Serializes the parallel mesh data.
This method serializes the base mesh data and all the additional data structures required for parallelization, such as the weak dual graph and the various numbering maps.
| Archive | The archive type (e.g., from Boost.Serialization). |
| ar | The archive to serialize to or from. |
|
friend |
Compares two ParallelMesh objects for equality.
| lhs | The left-hand side parallel mesh. |
| rhs | The right-hand side parallel mesh. |
|
protected |
number of ghost cells for each proc, only rank 0 knows it
|
protected |
global mesh partitioning, only rank 0 knows it
In each vector the last m_all_ghost_size indices indicate the ghost cells, the other indicate the owned cells
|
protected |
number of owned cells for each proc, only rank 0 knows it
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
number of edge cuts ParMetis makes
|
protected |
|
protected |
|
protected |
number of ghost [vtxs, edge, facet, cell] owned by this process, they are the last ones in the local numbering
|
protected |
global number of vertices, edges, faces, cells
|
protected |
global to local numbering of vertices, edges, faces, cells
Contains also ghost cells
|
protected |
local to global numbering of vertices, edges, faces, cells
Contains also ghost cells
|
protected |
number of [vtxs, edge, facet, cell] owned by this process
|
protected |
A unique pointer to the original mesh.
This is only valid on rank 0 after the parallelization process has begun.
|
protected |
|
protected |
cell to cell mapping of cells that share at least a vertex
|
inlinestaticconstexpr |
The dimension of the mesh (e.g., 2 for a 2D mesh, 3 for a 3D mesh).