ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
HaloPlanValidator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo 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 * ESPResSo 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#pragma once
20
21#include "cell_system/Cell.hpp"
22#include "ghosts/HaloPlan.hpp"
23
24#include <span>
25#include <string>
26#include <vector>
27
28namespace GhostComm {
29
30/**
31 * @brief Validate a HaloPlan for correctness.
32 *
33 * Checks:
34 * 1. Coverage: every ghost cell that a local cell references is filled.
35 * Point-to-point ghosts appear as a recv/local.dst target exactly once; no
36 * p2p target lies outside the ghost set; none appears twice. Ghosts filled
37 * by the collective broadcast/reduce section (AtomDecomposition,
38 * HybridDecomposition) are covered by that section instead of a recv/dst
39 * target. A ghost that no local cell references (e.g. the halo-layer cells
40 * on a single MPI rank, where the plan is intentionally empty) carries no
41 * physics and is not required to be filled.
42 * 2. Neighborship-match: every local cell's ghost neighbor is covered, either
43 * as a recv/dst target or by the collective section.
44 * 3. Peer-uniqueness: each peer value appears in at most one NeighborComm.
45 * 4. Shape: each NeighborComm has send.size() == recv.size().
46 * 5. Interior/boundary consistency: a cell marked interior has no ghost
47 * neighbor (enforced by mark_boundary_cells()).
48 * 6. Overlap-safety invariant: an interior cell must not appear as a
49 * NeighborComm send source or a LocalComm src. This is the exact
50 * precondition that the integrator step-2 / force-reduce overlap (Task
51 * 5.3) relies on: interior cells receive no reduce contributions and
52 * therefore do not require the reduce to complete before their velocity
53 * is updated. LocalComm.dst and NeighborComm.recv are ghost cells by
54 * construction (guaranteed by the dst-in-ghost-set coverage check #1),
55 * so they are not checked here.
56 *
57 * @returns a human-readable violation string per problem; empty = valid.
58 */
59std::vector<std::string> validate_halo_plan(HaloPlan const &plan,
60 std::span<Cell *const> local_cells,
61 std::span<Cell *const> ghost_cells);
62
63/**
64 * @brief Cross-rank symmetry check for a HaloPlan.
65 *
66 * Uses a collective all-to-all exchange of per-rank send-counts so that every
67 * rank participates regardless of whether the neighbor sets are symmetric.
68 * This avoids the deadlock that a naive per-neighbor isend/irecv pattern
69 * would cause when a rank sends to a peer that has no matching recv posted.
70 *
71 * Invariant: for every peer P, my recv-count from P must equal P's send-count
72 * to me (i.e. my_recv_from[P] == peers_send_to_me[P]).
73 *
74 * @returns a human-readable violation string per mismatch; empty = valid.
75 */
76std::vector<std::string> validate_halo_plan_symmetry(HaloPlan const &plan);
77
78/**
79 * @brief Print violations to stderr and return whether the list was empty.
80 *
81 * Intended for use inside assert(): a bare
82 * assert(validate_halo_plan(...).empty()) aborts without showing WHICH
83 * invariant failed, which makes CI failures undebuggable. Wrap the call:
84 * assert(GhostComm::report_violations(validate_halo_plan(...), "context")).
85 */
86bool report_violations(std::vector<std::string> const &violations,
87 char const *context);
88
89} // namespace GhostComm
bool report_violations(std::vector< std::string > const &violations, char const *context)
Print violations to stderr and return whether the list was empty.
std::vector< std::string > validate_halo_plan_symmetry(HaloPlan const &plan)
Cross-rank symmetry check for a HaloPlan.
std::vector< std::string > validate_halo_plan(HaloPlan const &plan, std::span< Cell *const > local_cells, std::span< Cell *const > ghost_cells)
Validate a HaloPlan for correctness.