MPI parallelization and domain decomposition for the flow solver.
This module manages the parallel execution of the hydrodynamic solver using a Replicated Mesh strategy. In this approach, every MPI rank holds the full topological structure of the mesh and globally sized field arrays, but performs physical updates (fluxes, source terms) only on owned cells or faces whose owner cell is owned locally.
Halo exchanges synchronize off-rank neighbor cells and shared face fluxes for stencil operations. Global reductions compute diagnostics and PCG dot products; gather routines are used for root-only output/diagnostics where needed.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | private | :: | mpi_started_here | = | .false. |
MPI context for hydrodynamic operations.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer, | public | :: | cell_halo_max_components | = | 4 | ||
| integer, | public, | allocatable | :: | cell_owner(:) | |||
| integer, | public, | allocatable | :: | cell_recv_cells(:) | |||
| integer, | public, | allocatable | :: | cell_recv_counts(:) | |||
| integer, | public, | allocatable | :: | cell_recv_displs(:) | |||
| integer, | public, | allocatable | :: | cell_recv_ranks(:) | |||
| real(kind=rk), | public, | allocatable | :: | cell_recvbuf(:) | |||
| type(MPI_Request), | public, | allocatable | :: | cell_requests(:) | |||
| integer, | public, | allocatable | :: | cell_send_cells(:) | |||
| integer, | public, | allocatable | :: | cell_send_counts(:) | |||
| integer, | public, | allocatable | :: | cell_send_displs(:) | |||
| integer, | public, | allocatable | :: | cell_send_ranks(:) | |||
| real(kind=rk), | public, | allocatable | :: | cell_sendbuf(:) | |||
| type(MPI_Comm), | public | :: | comm | = | MPI_COMM_NULL | ||
| integer, | public, | allocatable | :: | face_recv_counts(:) | |||
| integer, | public, | allocatable | :: | face_recv_displs(:) | |||
| integer, | public, | allocatable | :: | face_recv_faces(:) | |||
| integer, | public, | allocatable | :: | face_recv_ranks(:) | |||
| real(kind=rk), | public, | allocatable | :: | face_recvbuf(:) | |||
| type(MPI_Request), | public, | allocatable | :: | face_requests(:) | |||
| integer, | public, | allocatable | :: | face_send_counts(:) | |||
| integer, | public, | allocatable | :: | face_send_displs(:) | |||
| integer, | public, | allocatable | :: | face_send_faces(:) | |||
| integer, | public, | allocatable | :: | face_send_ranks(:) | |||
| real(kind=rk), | public, | allocatable | :: | face_sendbuf(:) | |||
| integer, | public | :: | first_cell | = | 0 | ||
| integer, | public, | allocatable | :: | gather_counts(:) | |||
| integer, | public, | allocatable | :: | gather_displs(:) | |||
| integer, | public, | allocatable | :: | gather_firsts(:) | |||
| integer, | public, | allocatable | :: | gather_matrix_counts(:) | |||
| integer, | public, | allocatable | :: | gather_matrix_displs(:) | |||
| real(kind=rk), | public, | allocatable | :: | gather_matrix_recvbuf(:) | |||
| real(kind=rk), | public, | allocatable | :: | gather_matrix_sendbuf(:) | |||
| integer, | public | :: | gather_max_components | = | 0 | ||
| real(kind=rk), | public, | allocatable | :: | gather_recvbuf(:) | |||
| real(kind=rk), | public, | allocatable | :: | gather_sendbuf(:) | |||
| integer, | public, | allocatable | :: | ghost_cells(:) | |||
| integer, | public | :: | last_cell | = | -1 | ||
| integer, | public | :: | ncell_recv_ranks | = | 0 | ||
| integer, | public | :: | ncell_send_ranks | = | 0 | ||
| integer, | public | :: | nface_recv_ranks | = | 0 | ||
| integer, | public | :: | nface_send_ranks | = | 0 | ||
| integer, | public | :: | nlocal | = | 0 | ||
| integer, | public | :: | nprocs | = | 0 | ||
| logical, | public, | allocatable | :: | owned(:) | |||
| integer, | public, | allocatable | :: | owned_faces(:) | |||
| integer, | public | :: | rank | = | -1 |
Computes the global dot product of two vectors over owned cells.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(in) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | a(:) | |||
| real(kind=rk), | intent(in) | :: | b(:) |
Computes the global maximum magnitude of a field over owned cells.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(in) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | a(:) |
Computes the global sum of a field over owned cells.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(in) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | a(:) |
Returns the mesh neighbor, using stored periodic links when present.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_t), | intent(in) | :: | mesh | |||
| integer, | intent(in) | :: | face_id | |||
| integer, | intent(in) | :: | cell_id |
Gathers locally-updated matrix cell values and broadcasts to the global mesh.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | local_global(:,:) | |||
| real(kind=rk), | intent(out) | :: | global(:,:) |
In-place variant for fields that already hold owned-cell updates.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(inout) | :: | field(:,:) |
Gathers locally-updated cell values and broadcasts to the global mesh.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | local_global(:) | |||
| real(kind=rk), | intent(out) | :: | global(:) |
Gathers 4-component cell values (e.g., Velocity + Scalar) in one call.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | local_v(:,:) | |||
| real(kind=rk), | intent(in) | :: | local_s(:) | |||
| real(kind=rk), | intent(out) | :: | global_v(:,:) | |||
| real(kind=rk), | intent(out) | :: | global_s(:) |
Gathers locally-updated 3D vector cell values and broadcasts to the global mesh.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | local_global(:,:) | |||
| real(kind=rk), | intent(out) | :: | global(:,:) |
Sum-Allreduce for a global scalar field.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(in) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | local_values(:) | |||
| real(kind=rk), | intent(out) | :: | global_values(:) |
Sum-Allreduce for a 3D global vector field.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(in) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | local_values(:,:) | |||
| real(kind=rk), | intent(out) | :: | global_values(:,:) |
Exchanges owned cell matrix values to ranks that keep them as ghosts.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(inout) | :: | field(:,:) |
Exchanges owned cell scalar values to ranks that keep them as ghosts.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(inout) | :: | field(:) |
Exchanges two to four related cell scalars in one halo transaction.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(inout) | :: | field1(:) | |||
| real(kind=rk), | intent(inout), | optional | :: | field2(:) | ||
| real(kind=rk), | intent(inout), | optional | :: | field3(:) | ||
| real(kind=rk), | intent(inout), | optional | :: | field4(:) |
Exchanges owner-computed face scalar values to ranks owning the neighbor cell.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(inout) | :: | face_field(:) |
Gathers owned matrix cell values to rank 0 only.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | field(:,:) | |||
| real(kind=rk), | intent(inout) | :: | root_field(:,:) |
Gathers owned scalar cell values to rank 0 only.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | field(:) | |||
| real(kind=rk), | intent(inout) | :: | root_field(:) |
Computes multiple global dot products in a single MPI_Allreduce.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(in) | :: | flow | |||
| integer, | intent(in) | :: | n_dots | |||
| real(kind=rk), | intent(in) | :: | a(:,:) | |||
| real(kind=rk), | intent(in) | :: | b(:,:) | |||
| real(kind=rk), | intent(out) | :: | results(:) |
Computes two global dot products without constructing temporary full-size batches.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(in) | :: | flow | |||
| real(kind=rk), | intent(in) | :: | a1(:) | |||
| real(kind=rk), | intent(in) | :: | b1(:) | |||
| real(kind=rk), | intent(in) | :: | a2(:) | |||
| real(kind=rk), | intent(in) | :: | b2(:) | |||
| real(kind=rk), | intent(out) | :: | results(2) |
Releases all MPI resources and buffers.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow |
Sets up domain decomposition for a given mesh.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_t), | intent(in) | :: | mesh |
The mesh to decompose. |
||
| type(flow_mpi_t), | intent(inout) | :: | flow |
The MPI context to populate. |
||
| type(MPI_Comm), | intent(in) | :: | comm_parent |
The parent communicator (usually MPI_COMM_WORLD). |
||
| integer, | intent(in), | optional | :: | max_gather_components |
Shuts down the MPI environment if it was started by this module.
Initializes the MPI environment if not already active.
Internal helper for MPI error checking.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | ierr | |||
| character(len=*), | intent(in) | :: | where |
Packs full per-rank metadata down to active communication partners.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | counts_all(:) | |||
| integer, | intent(in) | :: | displs_all(:) | |||
| integer, | intent(out) | :: | nactive | |||
| integer, | intent(out), | allocatable | :: | ranks(:) | ||
| integer, | intent(out), | allocatable | :: | counts(:) | ||
| integer, | intent(out), | allocatable | :: | displs(:) |
Converts per-rank counts to zero-based displacements.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | counts(:) | |||
| integer, | intent(out) | :: | displs(:) |
Updates cached count/displacement arrays for a packed component count.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| integer, | intent(in) | :: | ncomp | |||
| integer, | intent(in) | :: | ncells | |||
| integer, | intent(out) | :: | nlocal_comp |
Builds cell ghost send/receive metadata for one-ring neighbor stencils.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_t), | intent(in) | :: | mesh | |||
| type(flow_mpi_t), | intent(inout) | :: | flow |
Initializes contiguous-decomposition owner lookup.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_t), | intent(in) | :: | mesh | |||
| type(flow_mpi_t), | intent(inout) | :: | flow |
Builds face-flux halo metadata for shared internal faces.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_t), | intent(in) | :: | mesh | |||
| type(flow_mpi_t), | intent(inout) | :: | flow |
Caches faces whose owner cell belongs to this rank.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_t), | intent(in) | :: | mesh | |||
| type(flow_mpi_t), | intent(inout) | :: | flow |
Pre-calculates MPI gather offsets and counts for allgather operations.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(mesh_t), | intent(in) | :: | mesh | |||
| type(flow_mpi_t), | intent(inout) | :: | flow | |||
| integer, | intent(in), | optional | :: | max_gather_components |