pub(crate) mod sealed {
pub trait Sealed {}
}
pub trait Collectives: sealed::Sealed + Send + Sync {
fn rank(&self) -> u32;
fn size(&self) -> u32;
fn allreduce_max_u8(&self, v: u8) -> u8;
fn allreduce_sum_u64(&self, buffer: &mut [u64]);
fn allreduce_sum_f64(&self, buffer: &mut [f64]);
fn barrier(&self);
fn check_consistency(&self, fingerprint: u64) {
let mut counts = [0u64; 64];
for (i, count) in counts.iter_mut().enumerate() {
*count = (fingerprint >> i) & 1;
}
self.allreduce_sum_u64(&mut counts);
let size = u64::from(self.size());
for (bit, &count) in counts.iter().enumerate() {
assert!(
count == 0 || count == size,
"the partitions disagree about the run: partition {} offered fingerprint \
{fingerprint:#018x}, and {count} of {size} partitions set bit {bit} of theirs. \
Every partition must be driven through the same circuit, in the same direction, \
under the same policy and options — a group that is not stays in step only by \
luck.",
self.rank(),
);
}
}
}