Skip to content

Commit

Permalink
Allow specifying multiple read directories
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyBF committed Aug 12, 2024
1 parent 388932c commit 532a3fa
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion ext/src/chain_complex/chain_homotopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl<
.add_generators_from_rows_ooo(source.t(), outputs);
}

if let Some(dir) = self.save_dir.read() {
for dir in self.save_dir.read() {
if let Some(mut f) = self
.left
.source
Expand Down
15 changes: 8 additions & 7 deletions ext/src/nassau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ impl<M: ZeroModule<Algebra = MilnorAlgebra>> Resolution<M> {
return Ok(());
}

if let Some(dir) = self.save_dir.read() {
for dir in self.save_dir.read() {
if let Some(mut f) = self
.save_file(SaveKind::NassauDifferential, b)
.open_file(dir.clone())
Expand Down Expand Up @@ -1009,12 +1009,13 @@ impl<M: ZeroModule<Algebra = MilnorAlgebra>> ChainComplex for Resolution<M> {
for<'a> &'a mut T: Into<SliceMut<'a>>,
for<'a> &'a S: Into<Slice<'a>>,
{
let mut f = if let Some(dir) = self.save_dir.read() {
if let Some(f) = self.save_file(SaveKind::NassauQi, b).open_file(dir.clone()) {
f
} else {
return false;
}
let mut f = if let Some(f) = self
.save_dir
.read()
.flat_map(|dir| self.save_file(SaveKind::NassauQi, b).open_file(dir.clone()))
.next()
{
f
} else {
return false;
};
Expand Down
29 changes: 14 additions & 15 deletions ext/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ where

let p = self.prime();

if let Some(dir) = self.save_dir.read() {
for dir in self.save_dir.read() {
if let Some(mut f) = self.save_file(SaveKind::Kernel, b).open_file(dir.clone()) {
return Subspace::from_bytes(p, &mut f)
.with_context(|| format!("Failed to read kernel at {b}"))
Expand Down Expand Up @@ -370,7 +370,7 @@ where
target_res.compute_basis(b.t());
let target_res_dimension = target_res.dimension(b.t());

if let Some(dir) = self.save_dir.read() {
for dir in self.save_dir.read() {
if let Some(mut f) = self
.save_file(SaveKind::Differential, b)
.open_file(dir.clone())
Expand Down Expand Up @@ -814,12 +814,13 @@ where
} else if distance == 1 && b.s() < max.s() {
// We compute the kernel at the edge if necessary
let next_b = b + Bidegree::s_t(0, 1);
if !self.has_computed_bidegree(b + Bidegree::s_t(1, 1))
&& (self.save_dir.is_none()
|| !self
.save_file(SaveKind::Differential, b + Bidegree::s_t(1, 1))
.exists(self.save_dir.read().cloned().unwrap()))
{
let kernel_bidegree_not_computed =
!self.has_computed_bidegree(b + Bidegree::s_t(1, 1));
let save_does_not_exist = !self.save_dir.read().any(|dir| {
self.save_file(SaveKind::Differential, b + Bidegree::s_t(1, 1))
.exists(dir.clone())
});
if kernel_bidegree_not_computed && save_does_not_exist {
scope.spawn(move |_| {
self.kernels.insert(next_b, self.get_kernel(next_b));
SenderData::send(next_b, false, sender);
Expand Down Expand Up @@ -888,17 +889,15 @@ where
for (input, result) in inputs.iter().zip_eq(results) {
qi.apply(result.into(), 1, input.into());
}
true
} else if let Some(dir) = self.save_dir.read() {
return true;
}
for dir in self.save_dir.read() {
if let Some(mut f) = self.save_file(SaveKind::ResQi, b).open_file(dir.clone()) {
QuasiInverse::stream_quasi_inverse(self.prime(), &mut f, results, inputs).unwrap();
true
} else {
false
return true;
}
} else {
false
}
false
}

fn save_dir(&self) -> &SaveDirectory {
Expand Down
2 changes: 1 addition & 1 deletion ext/src/resolution_homomorphism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ where
);
}

if let Some(dir) = self.save_dir.read() {
for dir in self.save_dir.read() {
let mut outputs = Vec::with_capacity(num_gens);

if let Some(mut f) = self
Expand Down
15 changes: 11 additions & 4 deletions ext/src/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ pub enum SaveDirectory {
None,
Combined(PathBuf),
Split { read: PathBuf, write: PathBuf },
MultiRead { read: Vec<PathBuf>, write: PathBuf },
}

impl SaveDirectory {
pub fn read(&self) -> Option<&PathBuf> {
pub fn read(&self) -> Box<dyn Iterator<Item = &PathBuf> + '_> {
match self {
Self::None => None,
Self::Combined(x) => Some(x),
Self::Split { read, .. } => Some(read),
Self::None => Box::new(std::iter::empty()),
Self::Combined(x) => Box::new(std::iter::once(x)),
Self::Split { read, .. } => Box::new(std::iter::once(read)),
Self::MultiRead { read, .. } => Box::new(read.iter()),
}
}

Expand All @@ -32,6 +34,7 @@ impl SaveDirectory {
Self::None => None,
Self::Combined(x) => Some(x),
Self::Split { write, .. } => Some(write),
Self::MultiRead { write, .. } => Some(write),
}
}

Expand All @@ -45,6 +48,10 @@ impl SaveDirectory {
read.push(&p);
write.push(p);
}
Self::MultiRead { read, write } => {
read.iter_mut().for_each(|r| r.push(&p));
write.push(p);
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions ext/src/secondary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<A: PairAlgebra + Send + Sync> SecondaryHomotopy<A> {
b: gen.degree(),
idx: Some(gen.idx()),
};
if let Some(dir) = dir.read() {
for dir in dir.read() {
if let Some(mut f) = save_file.open_file(dir.to_owned()) {
return SecondaryComposite::from_bytes(
Arc::clone(&self.target),
Expand Down Expand Up @@ -421,7 +421,7 @@ pub trait SecondaryLift: Sync + Sized {
idx: Some(gen.idx()),
};

if let Some(dir) = self.save_dir().read() {
for dir in self.save_dir().read() {
if let Some(mut f) = save_file.open_file(dir.to_owned()) {
// The target dimension can depend on whether we resolved to stem
let dim = f.read_u64::<LittleEndian>().unwrap() as usize;
Expand Down Expand Up @@ -484,7 +484,7 @@ pub trait SecondaryLift: Sync + Sized {
return;
}
// Check if we have a saved homotopy
if let Some(dir) = self.save_dir().read() {
for dir in self.save_dir().read() {
let save_file = SaveFile {
algebra: self.algebra(),
kind: SaveKind::SecondaryHomotopy,
Expand Down Expand Up @@ -533,7 +533,7 @@ pub trait SecondaryLift: Sync + Sized {
let num_gens = source.number_of_gens_in_degree(b.t());
let target_dim = target.module(target_b.s()).dimension(target_b.t());

if let Some(dir) = self.save_dir().read() {
for dir in self.save_dir().read() {
let save_file = SaveFile {
algebra: self.algebra(),
kind: SaveKind::SecondaryHomotopy,
Expand Down

0 comments on commit 532a3fa

Please sign in to comment.