use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct PlanSummary {
pub(super) mesh: MeshId,
pub(super) hash: u64,
pub(super) collectives: usize,
}
impl PlanSummary {
#[must_use]
pub const fn from_parts(mesh: MeshId, hash: u64, collectives: usize) -> Self {
Self {
mesh,
hash,
collectives,
}
}
#[must_use]
pub const fn mesh_id(self) -> MeshId {
self.mesh
}
#[must_use]
pub const fn hash(self) -> u64 {
self.hash
}
#[must_use]
pub const fn collective_count(self) -> usize {
self.collectives
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AgreedPlan {
summary: PlanSummary,
ranks: usize,
}
impl AgreedPlan {
#[must_use]
pub const fn summary(self) -> PlanSummary {
self.summary
}
#[must_use]
pub const fn ranks(self) -> usize {
self.ranks
}
}
pub fn preflight(
expected_ranks: usize,
summaries: &[PlanSummary],
) -> Result<AgreedPlan, PlanError> {
if expected_ranks == 0 {
return Err(PlanError::EmptyPreflight);
}
if summaries.len() != expected_ranks {
return Err(PlanError::PreflightRankCount {
expected: expected_ranks,
found: summaries.len(),
});
}
let expected = summaries[0];
for (rank, &found) in summaries.iter().enumerate().skip(1) {
if found.mesh != expected.mesh {
return Err(PlanError::MeshMismatch {
rank,
expected: expected.mesh,
found: found.mesh,
});
}
if found.collectives != expected.collectives {
return Err(PlanError::CollectiveCountMismatch {
rank,
expected: expected.collectives,
found: found.collectives,
});
}
if found.hash != expected.hash {
return Err(PlanError::PlanHashMismatch {
rank,
expected: expected.hash,
found: found.hash,
});
}
}
Ok(AgreedPlan {
summary: expected,
ranks: expected_ranks,
})
}