Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cpp/monoprop/detail/partition/CpuTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <mutex>
#include <print>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -343,6 +344,17 @@
summary.cpu_list);
}

auto place_line_is_new(std::string_view line) -> bool {
static std::mutex mu;
static std::string last;
const std::lock_guard lock(mu);

Check warning on line 350 in cpp/monoprop/detail/partition/CpuTopology.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy analysis

use 'std::scoped_lock' instead of 'std::lock_guard' [modernize-use-scoped-lock]
if (line == last) {
return false;
}
last = line;
return true;
}

/* ── partition_cpusets ─────────────────────────────────────────────────────── */

auto partition_cpusets(size_t n, size_t group_index, size_t group_count, NodeMask mask) -> std::vector<CpuSet> {
Expand Down
8 changes: 8 additions & 0 deletions cpp/monoprop/detail/partition/CpuTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <cstdint>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

namespace monoprop::detail::partition {
Expand Down Expand Up @@ -131,6 +132,13 @@ struct MaskSummary {
const char *verdict,
const MaskSummary &summary) -> std::string;

/*! @brief True the first time @p line is seen, and whenever it differs from the previous call.
* One process has one placement, so a propagator built 437 times reports it 437 times identically;
* the whole line is compared rather than a once-flag set, because a process that builds an `alone`
* propagator before an MPI one has two placements and both are worth saying. Process-wide, locked.
*/
[[nodiscard]] auto place_line_is_new(std::string_view line) -> bool;

//! Whether the launcher has already handed this rank a private slice of the node, or the node's CPUs are shared.
enum class NodeMask { Shared, PerRank };

Expand Down
18 changes: 10 additions & 8 deletions cpp/monoprop/detail/partition/PartitionGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <type_traits>
#include <vector>
Expand Down Expand Up @@ -211,14 +212,15 @@ class PartitionGroup {
}
// No summary is "unknown" rather than a plausible zero: some mask did not fit the window.
const auto sum = summarize_masks(masks, peers, kWords, static_cast<size_t>(node_rank_));
std::fputs(format_place_line(mpi::rank(parent_),
node_rank_,
node_size_,
sum ? verdict : "unknown",
sum.value_or(MaskSummary{}))
.c_str(),
stderr);
std::fflush(stderr);
const std::string line = format_place_line(mpi::rank(parent_),
node_rank_,
node_size_,
sum ? verdict : "unknown",
sum.value_or(MaskSummary{}));
if (place_line_is_new(line)) {
std::fputs(line.c_str(), stderr);
std::fflush(stderr);
}
}

auto make_transport_() -> void {
Expand Down
13 changes: 13 additions & 0 deletions cpp/tests/cpu_topology_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,19 @@ BOOST_AUTO_TEST_CASE(cpu_topology_place_line_reports_every_field) {
"cpu_list=0-127\n");
}

// 437 identical lines in one 585-test run is noise; a CHANGED line still has to get through.
BOOST_AUTO_TEST_CASE(cpu_topology_place_line_repeats_are_collapsed) {
// Distinctive, so a real COMMPLACE line emitted by some other case cannot be the previous value.
const std::string a = "COMMPLACE test-a\n";
const std::string b = "COMMPLACE test-b\n";
BOOST_CHECK(partition::place_line_is_new(a));
BOOST_CHECK(!partition::place_line_is_new(a));
BOOST_CHECK(!partition::place_line_is_new(a));
BOOST_CHECK(partition::place_line_is_new(b)); // a different placement is not a repeat
BOOST_CHECK(!partition::place_line_is_new(b));
BOOST_CHECK(partition::place_line_is_new(a)); // and neither is coming back to the first one
}

// The state summarize_masks refuses to classify must SAY unknown rather than print a plausible zero.
BOOST_AUTO_TEST_CASE(cpu_topology_place_line_unknown_is_not_a_verdict) {
BOOST_CHECK_EQUAL(partition::format_place_line(0, 0, 1, "unknown", partition::MaskSummary{}),
Expand Down
Loading