From 2152b68f278d9e00937db180e85ed965a3b4359d Mon Sep 17 00:00:00 2001 From: Juniper Tyree Date: Sun, 2 Jun 2024 06:54:13 +0000 Subject: [PATCH] Partially revert aa36dc954df8c4edd9f976deaf6bfe7f213f2a86 --- .../independent/individuals.rs | 3 +- .../parallelisation/independent/landscape.rs | 3 +- .../independent/monolithic/mod.rs | 3 +- .../independent/monolithic/reporter/live.rs | 26 +++++++++------ .../independent/monolithic/reporter/mod.rs | 21 ++++++------ .../monolithic/reporter/recorded.rs | 22 +++++++------ .../parallelisation/independent/reporter.rs | 24 ++++++++------ .../parallelisation/monolithic/averaging.rs | 3 +- .../parallelisation/monolithic/lockstep.rs | 3 +- .../parallelisation/monolithic/monolithic.rs | 3 +- .../parallelisation/monolithic/optimistic.rs | 3 +- .../monolithic/optimistic_lockstep.rs | 3 +- .../parallelisation/monolithic/reporter.rs | 26 ++++++++------- necsim/partitioning/core/src/lib.rs | 13 +++++--- necsim/partitioning/monolithic/src/lib.rs | 13 +++++--- necsim/partitioning/monolithic/src/live.rs | 9 +++-- .../partitioning/monolithic/src/recorded.rs | 9 +++-- necsim/partitioning/mpi/src/lib.rs | 10 ++---- necsim/partitioning/mpi/src/partition/mod.rs | 7 ++-- .../mpi/src/partition/parallel.rs | 7 ++-- necsim/partitioning/mpi/src/partition/root.rs | 7 ++-- necsim/partitioning/threads/src/lib.rs | 4 +-- necsim/partitioning/threads/src/partition.rs | 9 +++-- rustcoalescence/algorithms/cuda/src/launch.rs | 3 +- rustcoalescence/algorithms/cuda/src/lib.rs | 7 ++-- .../cuda/src/parallelisation/monolithic.rs | 6 ++-- .../algorithms/gillespie/src/arguments.rs | 2 +- .../src/event_skipping/initialiser/fixup.rs | 3 +- .../src/event_skipping/initialiser/genesis.rs | 3 +- .../src/event_skipping/initialiser/mod.rs | 3 +- .../src/event_skipping/initialiser/resume.rs | 3 +- .../gillespie/src/event_skipping/launch.rs | 3 +- .../gillespie/src/event_skipping/mod.rs | 12 +++++-- .../gillespie/classical/initialiser/fixup.rs | 3 +- .../classical/initialiser/genesis.rs | 3 +- .../gillespie/classical/initialiser/mod.rs | 3 +- .../gillespie/classical/initialiser/resume.rs | 3 +- .../src/gillespie/classical/launch.rs | 3 +- .../gillespie/src/gillespie/classical/mod.rs | 5 +-- .../algorithms/gillespie/src/gillespie/mod.rs | 2 +- .../gillespie/turnover/initialiser/fixup.rs | 3 +- .../gillespie/turnover/initialiser/genesis.rs | 3 +- .../src/gillespie/turnover/initialiser/mod.rs | 3 +- .../gillespie/turnover/initialiser/resume.rs | 3 +- .../src/gillespie/turnover/launch.rs | 3 +- .../gillespie/src/gillespie/turnover/mod.rs | 10 ++++-- .../algorithms/independent/src/launch.rs | 3 +- .../algorithms/independent/src/lib.rs | 12 +++++-- rustcoalescence/algorithms/src/lib.rs | 13 ++++++-- .../src/cli/simulate/dispatch/valid/launch.rs | 5 +-- .../simulate/dispatch/valid/partitioning.rs | 33 ++++++++++--------- 51 files changed, 243 insertions(+), 146 deletions(-) diff --git a/necsim/impls/no-std/src/parallelisation/independent/individuals.rs b/necsim/impls/no-std/src/parallelisation/independent/individuals.rs index 5810ef688..6182e0947 100644 --- a/necsim/impls/no-std/src/parallelisation/independent/individuals.rs +++ b/necsim/impls/no-std/src/parallelisation/independent/individuals.rs @@ -36,6 +36,7 @@ use super::{reporter::IgnoreProgressReporterProxy, DedupCache}; #[allow(clippy::type_complexity)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, G: PrimeableRng, @@ -56,7 +57,7 @@ pub fn simulate< NeverImmigrationEntry, >, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, L: IntoIterator, >( simulation: &mut Simulation< diff --git a/necsim/impls/no-std/src/parallelisation/independent/landscape.rs b/necsim/impls/no-std/src/parallelisation/independent/landscape.rs index f5540bd1f..2a28c8ea3 100644 --- a/necsim/impls/no-std/src/parallelisation/independent/landscape.rs +++ b/necsim/impls/no-std/src/parallelisation/independent/landscape.rs @@ -39,6 +39,7 @@ use super::{reporter::IgnoreProgressReporterProxy, DedupCache}; #[allow(clippy::type_complexity, clippy::too_many_lines)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, C: Decomposition, @@ -61,7 +62,7 @@ pub fn simulate< NeverImmigrationEntry, >, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, L: IntoIterator, >( simulation: &mut Simulation< diff --git a/necsim/impls/no-std/src/parallelisation/independent/monolithic/mod.rs b/necsim/impls/no-std/src/parallelisation/independent/monolithic/mod.rs index 639558a66..6bc67feaa 100644 --- a/necsim/impls/no-std/src/parallelisation/independent/monolithic/mod.rs +++ b/necsim/impls/no-std/src/parallelisation/independent/monolithic/mod.rs @@ -41,6 +41,7 @@ use reporter::{ #[allow(clippy::type_complexity, clippy::too_many_lines)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, G: PrimeableRng, @@ -61,7 +62,7 @@ pub fn simulate< NeverImmigrationEntry, >, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, L: IntoIterator, >( simulation: &mut Simulation< diff --git a/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/live.rs b/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/live.rs index 0c22a60bc..24bb72672 100644 --- a/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/live.rs +++ b/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/live.rs @@ -13,16 +13,18 @@ use necsim_partitioning_core::LocalPartition; use super::WaterLevelReporterProxy; #[allow(clippy::module_name_repetitions)] -pub struct LiveWaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition> { +pub struct LiveWaterLevelReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> { water_level: NonNegativeF64, slow_events: Vec, fast_events: Vec, - local_partition: &'p mut P, - _marker: PhantomData, + local_partition: &'l mut P, + _marker: PhantomData<(&'p (), R)>, } -impl<'p, R: Reporter, P: LocalPartition> fmt::Debug for LiveWaterLevelReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug + for LiveWaterLevelReporterProxy<'l, 'p, R, P> +{ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { struct EventBufferLen(usize); @@ -40,7 +42,9 @@ impl<'p, R: Reporter, P: LocalPartition> fmt::Debug for LiveWaterLevelReporte } } -impl<'p, R: Reporter, P: LocalPartition> Reporter for LiveWaterLevelReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter + for LiveWaterLevelReporterProxy<'l, 'p, R, P> +{ impl_report!(speciation(&mut self, speciation: MaybeUsed) { if speciation.event_time < self.water_level { self.slow_events.push(speciation.clone().into()); @@ -61,10 +65,10 @@ impl<'p, R: Reporter, P: LocalPartition> Reporter for LiveWaterLevelReporterP } #[contract_trait] -impl<'p, R: Reporter, P: LocalPartition> WaterLevelReporterProxy<'p, R, P> - for LiveWaterLevelReporterProxy<'p, R, P> +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> WaterLevelReporterProxy<'l, 'p, R, P> + for LiveWaterLevelReporterProxy<'l, 'p, R, P> { - fn new(capacity: usize, local_partition: &'p mut P) -> Self { + fn new(capacity: usize, local_partition: &'l mut P) -> Self { info!("Events will be reported using the live water-level algorithm ..."); Self { @@ -73,7 +77,7 @@ impl<'p, R: Reporter, P: LocalPartition> WaterLevelReporterProxy<'p, R, P> fast_events: Vec::with_capacity(capacity), local_partition, - _marker: PhantomData::, + _marker: PhantomData::<(&'p (), R)>, } } @@ -115,7 +119,9 @@ impl<'p, R: Reporter, P: LocalPartition> WaterLevelReporterProxy<'p, R, P> } } -impl<'p, R: Reporter, P: LocalPartition> Drop for LiveWaterLevelReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Drop + for LiveWaterLevelReporterProxy<'l, 'p, R, P> +{ fn drop(&mut self) { // Report all events below the water level in sorted order self.slow_events.sort_unstable(); diff --git a/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/mod.rs b/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/mod.rs index 5c4e5dfa2..7df56366e 100644 --- a/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/mod.rs +++ b/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/mod.rs @@ -13,7 +13,7 @@ mod recorded; #[allow(clippy::inline_always, clippy::inline_fn_without_body)] #[allow(clippy::no_effect_underscore_binding)] #[contract_trait] -pub trait WaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition>: +pub trait WaterLevelReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>>: Sized + Reporter< ReportSpeciation = R::ReportSpeciation, @@ -21,7 +21,7 @@ pub trait WaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition>: ReportProgress = False, > { - fn new(capacity: usize, local_partition: &'p mut P) -> Self; + fn new(capacity: usize, local_partition: &'l mut P) -> Self; fn water_level(&self) -> NonNegativeF64; @@ -36,23 +36,24 @@ pub trait WaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition>: pub enum WaterLevelReporterStrategy {} pub trait WaterLevelReporterConstructor< + 'l, 'p, IsLive: Boolean, R: Reporter, - P: 'p + LocalPartition, + P: 'l + LocalPartition<'p, R, IsLive = IsLive>, > { - type WaterLevelReporter: WaterLevelReporterProxy<'p, R, P>; + type WaterLevelReporter: WaterLevelReporterProxy<'l, 'p, R, P>; } -impl<'p, IsLive: Boolean, R: Reporter, P: 'p + LocalPartition> - WaterLevelReporterConstructor<'p, IsLive, R, P> for WaterLevelReporterStrategy +impl<'l, 'p, IsLive: Boolean, R: Reporter, P: 'l + LocalPartition<'p, R, IsLive = IsLive>> + WaterLevelReporterConstructor<'l, 'p, IsLive, R, P> for WaterLevelReporterStrategy { - default type WaterLevelReporter = live::LiveWaterLevelReporterProxy<'p, R, P>; + default type WaterLevelReporter = live::LiveWaterLevelReporterProxy<'l, 'p, R, P>; } -impl<'p, R: Reporter, P: 'p + LocalPartition> - WaterLevelReporterConstructor<'p, False, R, P> for WaterLevelReporterStrategy +impl<'l, 'p, R: Reporter, P: 'l + LocalPartition<'p, R, IsLive = False>> + WaterLevelReporterConstructor<'l, 'p, False, R, P> for WaterLevelReporterStrategy { - type WaterLevelReporter = recorded::RecordedWaterLevelReporterProxy<'p, R, P>; + type WaterLevelReporter = recorded::RecordedWaterLevelReporterProxy<'l, 'p, R, P>; } diff --git a/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/recorded.rs b/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/recorded.rs index cebf47912..455313de5 100644 --- a/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/recorded.rs +++ b/necsim/impls/no-std/src/parallelisation/independent/monolithic/reporter/recorded.rs @@ -8,15 +8,15 @@ use necsim_partitioning_core::LocalPartition; use super::WaterLevelReporterProxy; #[allow(clippy::module_name_repetitions)] -pub struct RecordedWaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition> { +pub struct RecordedWaterLevelReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> { water_level: NonNegativeF64, - local_partition: &'p mut P, - _marker: PhantomData, + local_partition: &'l mut P, + _marker: PhantomData<(&'p (), R)>, } -impl<'p, R: Reporter, P: LocalPartition> fmt::Debug - for RecordedWaterLevelReporterProxy<'p, R, P> +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug + for RecordedWaterLevelReporterProxy<'l, 'p, R, P> { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct(stringify!(RecordedWaterLevelReporterProxy)) @@ -25,7 +25,9 @@ impl<'p, R: Reporter, P: LocalPartition> fmt::Debug } } -impl<'p, R: Reporter, P: LocalPartition> Reporter for RecordedWaterLevelReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter + for RecordedWaterLevelReporterProxy<'l, 'p, R, P> +{ impl_report!(speciation(&mut self, speciation: MaybeUsed) { self.local_partition.get_reporter().report_speciation(speciation.into()); }); @@ -38,17 +40,17 @@ impl<'p, R: Reporter, P: LocalPartition> Reporter for RecordedWaterLevelRepor } #[contract_trait] -impl<'p, R: Reporter, P: LocalPartition> WaterLevelReporterProxy<'p, R, P> - for RecordedWaterLevelReporterProxy<'p, R, P> +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> WaterLevelReporterProxy<'l, 'p, R, P> + for RecordedWaterLevelReporterProxy<'l, 'p, R, P> { - fn new(_capacity: usize, local_partition: &'p mut P) -> Self { + fn new(_capacity: usize, local_partition: &'l mut P) -> Self { info!("Events will be reported using the recorded water-level algorithm ..."); Self { water_level: NonNegativeF64::zero(), local_partition, - _marker: PhantomData::, + _marker: PhantomData::<(&'p (), R)>, } } diff --git a/necsim/impls/no-std/src/parallelisation/independent/reporter.rs b/necsim/impls/no-std/src/parallelisation/independent/reporter.rs index 76c178e10..a8e84caa1 100644 --- a/necsim/impls/no-std/src/parallelisation/independent/reporter.rs +++ b/necsim/impls/no-std/src/parallelisation/independent/reporter.rs @@ -4,27 +4,31 @@ use necsim_core::{impl_report, reporter::Reporter}; use necsim_partitioning_core::LocalPartition; -pub struct IgnoreProgressReporterProxy<'p, R: Reporter, P: LocalPartition> { - local_partition: &'p mut P, - _marker: PhantomData, +pub struct IgnoreProgressReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> { + local_partition: &'l mut P, + _marker: PhantomData<(&'p (), R)>, } -impl<'p, R: Reporter, P: LocalPartition> fmt::Debug for IgnoreProgressReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug + for IgnoreProgressReporterProxy<'l, 'p, R, P> +{ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.debug_struct(stringify!(IgnoreProgressReporterProxy)) .finish() } } -impl<'p, R: Reporter, P: LocalPartition> Reporter for IgnoreProgressReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter + for IgnoreProgressReporterProxy<'l, 'p, R, P> +{ impl_report!(speciation(&mut self, speciation: MaybeUsed< - <

>::Reporter as Reporter + <

>::Reporter as Reporter >::ReportSpeciation>) { self.local_partition.get_reporter().report_speciation(speciation.into()); }); impl_report!(dispersal(&mut self, dispersal: MaybeUsed< - <

>::Reporter as Reporter + <

>::Reporter as Reporter >::ReportDispersal>) { self.local_partition.get_reporter().report_dispersal(dispersal.into()); }); @@ -32,11 +36,11 @@ impl<'p, R: Reporter, P: LocalPartition> Reporter for IgnoreProgressReporterP impl_report!(progress(&mut self, _progress: Ignored) {}); } -impl<'p, R: Reporter, P: LocalPartition> IgnoreProgressReporterProxy<'p, R, P> { - pub fn from(local_partition: &'p mut P) -> Self { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> IgnoreProgressReporterProxy<'l, 'p, R, P> { + pub fn from(local_partition: &'l mut P) -> Self { Self { local_partition, - _marker: PhantomData::, + _marker: PhantomData::<(&'p (), R)>, } } diff --git a/necsim/impls/no-std/src/parallelisation/monolithic/averaging.rs b/necsim/impls/no-std/src/parallelisation/monolithic/averaging.rs index 3f9f2ab5d..b255c2ab0 100644 --- a/necsim/impls/no-std/src/parallelisation/monolithic/averaging.rs +++ b/necsim/impls/no-std/src/parallelisation/monolithic/averaging.rs @@ -23,6 +23,7 @@ use crate::{ #[allow(clippy::type_complexity)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, G: RngCore, @@ -47,7 +48,7 @@ pub fn simulate< BufferedImmigrationEntry, >, P: Reporter, - L: LocalPartition

, + L: LocalPartition<'p, P>, >( simulation: &mut Simulation< M, diff --git a/necsim/impls/no-std/src/parallelisation/monolithic/lockstep.rs b/necsim/impls/no-std/src/parallelisation/monolithic/lockstep.rs index b1cb18051..f1ff75edc 100644 --- a/necsim/impls/no-std/src/parallelisation/monolithic/lockstep.rs +++ b/necsim/impls/no-std/src/parallelisation/monolithic/lockstep.rs @@ -23,6 +23,7 @@ use crate::{ #[allow(clippy::type_complexity)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, G: RngCore, @@ -47,7 +48,7 @@ pub fn simulate< BufferedImmigrationEntry, >, P: Reporter, - L: LocalPartition

, + L: LocalPartition<'p, P>, >( simulation: &mut Simulation< M, diff --git a/necsim/impls/no-std/src/parallelisation/monolithic/monolithic.rs b/necsim/impls/no-std/src/parallelisation/monolithic/monolithic.rs index 2fd8aebcb..86c1f2418 100644 --- a/necsim/impls/no-std/src/parallelisation/monolithic/monolithic.rs +++ b/necsim/impls/no-std/src/parallelisation/monolithic/monolithic.rs @@ -22,6 +22,7 @@ use crate::{ #[allow(clippy::type_complexity)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, G: RngCore, @@ -33,7 +34,7 @@ pub fn simulate< E: EventSampler, A: ActiveLineageSampler, P: Reporter, - L: LocalPartition

, + L: LocalPartition<'p, P>, >( simulation: &mut Simulation< M, diff --git a/necsim/impls/no-std/src/parallelisation/monolithic/optimistic.rs b/necsim/impls/no-std/src/parallelisation/monolithic/optimistic.rs index 70bcc2e59..ee9a55a49 100644 --- a/necsim/impls/no-std/src/parallelisation/monolithic/optimistic.rs +++ b/necsim/impls/no-std/src/parallelisation/monolithic/optimistic.rs @@ -28,6 +28,7 @@ use super::reporter::BufferingReporterProxy; #[allow(clippy::type_complexity)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, G: RngCore, @@ -52,7 +53,7 @@ pub fn simulate< BufferedImmigrationEntry, >, P: Reporter, - L: LocalPartition

, + L: LocalPartition<'p, P>, >( simulation: &mut Simulation< M, diff --git a/necsim/impls/no-std/src/parallelisation/monolithic/optimistic_lockstep.rs b/necsim/impls/no-std/src/parallelisation/monolithic/optimistic_lockstep.rs index b09b1cc8f..d9cdab94d 100644 --- a/necsim/impls/no-std/src/parallelisation/monolithic/optimistic_lockstep.rs +++ b/necsim/impls/no-std/src/parallelisation/monolithic/optimistic_lockstep.rs @@ -23,6 +23,7 @@ use crate::{ #[allow(clippy::type_complexity)] pub fn simulate< + 'p, M: MathsCore, H: Habitat, G: RngCore, @@ -47,7 +48,7 @@ pub fn simulate< BufferedImmigrationEntry, >, P: Reporter, - L: LocalPartition

, + L: LocalPartition<'p, P>, >( simulation: &mut Simulation< M, diff --git a/necsim/impls/no-std/src/parallelisation/monolithic/reporter.rs b/necsim/impls/no-std/src/parallelisation/monolithic/reporter.rs index 3e8278d65..fa181ffff 100644 --- a/necsim/impls/no-std/src/parallelisation/monolithic/reporter.rs +++ b/necsim/impls/no-std/src/parallelisation/monolithic/reporter.rs @@ -9,13 +9,15 @@ use necsim_core::{ use necsim_partitioning_core::LocalPartition; -pub struct BufferingReporterProxy<'p, R: Reporter, P: LocalPartition> { - local_partition: &'p mut P, +pub struct BufferingReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> { + local_partition: &'l mut P, event_buffer: Vec, - _marker: PhantomData, + _marker: PhantomData<(&'p (), R)>, } -impl<'p, R: Reporter, P: LocalPartition> fmt::Debug for BufferingReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug + for BufferingReporterProxy<'l, 'p, R, P> +{ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { struct EventBufferLen(usize); @@ -31,32 +33,34 @@ impl<'p, R: Reporter, P: LocalPartition> fmt::Debug for BufferingReporterProx } } -impl<'p, R: Reporter, P: LocalPartition> Reporter for BufferingReporterProxy<'p, R, P> { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter + for BufferingReporterProxy<'l, 'p, R, P> +{ impl_report!(speciation(&mut self, speciation: MaybeUsed< - <

>::Reporter as Reporter + <

>::Reporter as Reporter >::ReportSpeciation>) { self.event_buffer.push(speciation.clone().into()); }); impl_report!(dispersal(&mut self, dispersal: MaybeUsed< - <

>::Reporter as Reporter + <

>::Reporter as Reporter >::ReportDispersal>) { self.event_buffer.push(dispersal.clone().into()); }); impl_report!(progress(&mut self, progress: MaybeUsed< - <

>::Reporter as Reporter + <

>::Reporter as Reporter >::ReportProgress>) { self.local_partition.get_reporter().report_progress(progress.into()); }); } -impl<'p, R: Reporter, P: LocalPartition> BufferingReporterProxy<'p, R, P> { - pub fn from(local_partition: &'p mut P) -> Self { +impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> BufferingReporterProxy<'l, 'p, R, P> { + pub fn from(local_partition: &'l mut P) -> Self { Self { local_partition, event_buffer: Vec::new(), - _marker: PhantomData::, + _marker: PhantomData::<(&'p (), R)>, } } diff --git a/necsim/partitioning/core/src/lib.rs b/necsim/partitioning/core/src/lib.rs index 24a31160a..6671d24ea 100644 --- a/necsim/partitioning/core/src/lib.rs +++ b/necsim/partitioning/core/src/lib.rs @@ -19,7 +19,7 @@ use partition::{Partition, PartitionSize}; use reporter::{FinalisableReporter, ReporterContext}; pub trait Partitioning: Sized { - type LocalPartition: LocalPartition; + type LocalPartition<'p, R: Reporter>: LocalPartition<'p, R>; type FinalisableReporter: FinalisableReporter; type Auxiliary; @@ -36,7 +36,7 @@ pub trait Partitioning: Sized { reporter_context: P, auxiliary: Self::Auxiliary, args: A, - inner: fn(&mut Self::LocalPartition, A) -> Q, + inner: for<'p> fn(&mut Self::LocalPartition<'p, R>, A) -> Q, fold: fn(Q, Q) -> Q, ) -> anyhow::Result<(Q, Self::FinalisableReporter)>; } @@ -51,12 +51,13 @@ pub enum MigrationMode { Hold, } -pub trait LocalPartition: Sized { +pub trait LocalPartition<'p, R: Reporter>: Sized { type Reporter: Reporter; type IsLive: Boolean; type ImmigrantIterator<'a>: Iterator where - Self: 'a; + Self: 'a, + 'p: 'a; fn get_reporter(&mut self) -> &mut Self::Reporter; @@ -67,7 +68,9 @@ pub trait LocalPartition: Sized { emigrants: &mut E, emigration_mode: MigrationMode, immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a>; + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a; fn reduce_vote_any(&mut self, vote: bool) -> bool; diff --git a/necsim/partitioning/monolithic/src/lib.rs b/necsim/partitioning/monolithic/src/lib.rs index ba7e89a1a..9e872ac01 100644 --- a/necsim/partitioning/monolithic/src/lib.rs +++ b/necsim/partitioning/monolithic/src/lib.rs @@ -52,7 +52,7 @@ impl<'de> Deserialize<'de> for MonolithicPartitioning { impl Partitioning for MonolithicPartitioning { type Auxiliary = Option; type FinalisableReporter = FinalisableMonolithicReporter; - type LocalPartition = MonolithicLocalPartition; + type LocalPartition<'p, R: Reporter> = MonolithicLocalPartition; fn get_size(&self) -> PartitionSize { PartitionSize::MONOLITHIC @@ -66,7 +66,7 @@ impl Partitioning for MonolithicPartitioning { reporter_context: P, event_log: Self::Auxiliary, args: A, - inner: fn(&mut Self::LocalPartition, A) -> Q, + inner: for<'p> fn(&mut Self::LocalPartition<'p, R>, A) -> Q, _fold: fn(Q, Q) -> Q, ) -> anyhow::Result<(Q, Self::FinalisableReporter)> { let mut local_partition = if let Some(event_log) = event_log { @@ -95,8 +95,8 @@ pub enum MonolithicLocalPartition { Recorded(Box>), } -impl LocalPartition for MonolithicLocalPartition { - type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where R: 'a; +impl<'p, R: Reporter> LocalPartition<'p, R> for MonolithicLocalPartition { + type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where 'p: 'a, R: 'a; // pessimistic type IsLive = True; type Reporter = Self; @@ -117,7 +117,10 @@ impl LocalPartition for MonolithicLocalPartition { emigrants: &mut E, emigration_mode: MigrationMode, immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a> { + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a, + { match self { Self::Live(partition) => { partition.migrate_individuals(emigrants, emigration_mode, immigration_mode) diff --git a/necsim/partitioning/monolithic/src/live.rs b/necsim/partitioning/monolithic/src/live.rs index 313226682..3d9337065 100644 --- a/necsim/partitioning/monolithic/src/live.rs +++ b/necsim/partitioning/monolithic/src/live.rs @@ -33,8 +33,8 @@ impl fmt::Debug for LiveMonolithicLocalPartition { } } -impl LocalPartition for LiveMonolithicLocalPartition { - type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where R: 'a; +impl<'p, R: Reporter> LocalPartition<'p, R> for LiveMonolithicLocalPartition { + type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where 'p: 'a, R: 'a; type IsLive = True; type Reporter = FilteredReporter; @@ -51,7 +51,10 @@ impl LocalPartition for LiveMonolithicLocalPartition { emigrants: &mut E, _emigration_mode: MigrationMode, _immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a> { + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a, + { for (_, emigrant) in emigrants { self.loopback.push(emigrant); } diff --git a/necsim/partitioning/monolithic/src/recorded.rs b/necsim/partitioning/monolithic/src/recorded.rs index aeea2495a..7ece1c10b 100644 --- a/necsim/partitioning/monolithic/src/recorded.rs +++ b/necsim/partitioning/monolithic/src/recorded.rs @@ -43,8 +43,8 @@ impl fmt::Debug for RecordedMonolithicLocalPartition { } } -impl LocalPartition for RecordedMonolithicLocalPartition { - type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where R: 'a; +impl<'p, R: Reporter> LocalPartition<'p, R> for RecordedMonolithicLocalPartition { + type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where 'p: 'a, R: 'a; type IsLive = False; type Reporter = Self; @@ -61,7 +61,10 @@ impl LocalPartition for RecordedMonolithicLocalPartition { emigrants: &mut E, _emigration_mode: MigrationMode, _immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a> { + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a, + { for (_, emigrant) in emigrants { self.loopback.push(emigrant); } diff --git a/necsim/partitioning/mpi/src/lib.rs b/necsim/partitioning/mpi/src/lib.rs index 61175598d..f61599648 100644 --- a/necsim/partitioning/mpi/src/lib.rs +++ b/necsim/partitioning/mpi/src/lib.rs @@ -167,7 +167,7 @@ impl MpiPartitioning { impl Partitioning for MpiPartitioning { type Auxiliary = Option; type FinalisableReporter = FinalisableMpiReporter; - type LocalPartition = MpiLocalPartition<'static, R>; + type LocalPartition<'p, R: Reporter> = MpiLocalPartition<'p, R>; fn get_size(&self) -> PartitionSize { #[allow(clippy::cast_sign_loss)] @@ -191,7 +191,7 @@ impl Partitioning for MpiPartitioning { reporter_context: P, event_log: Self::Auxiliary, args: A, - inner: fn(&mut Self::LocalPartition, A) -> Q, + inner: for<'p> fn(&mut Self::LocalPartition<'p, R>, A) -> Q, fold: fn(Q, Q) -> Q, ) -> anyhow::Result<(Q, Self::FinalisableReporter)> { let Some(event_log) = event_log else { @@ -223,7 +223,7 @@ impl Partitioning for MpiPartitioning { .collect::>() .into_boxed_slice(); - let local_partition = if self.world.rank() == MpiPartitioning::ROOT_RANK { + let mut local_partition = if self.world.rank() == MpiPartitioning::ROOT_RANK { MpiLocalPartition::Root(Box::new(MpiRootPartition::new( ManuallyDrop::into_inner(self.universe), mpi_local_global_wait, @@ -244,10 +244,6 @@ impl Partitioning for MpiPartitioning { self.progress_interval, ))) }; - // TODO: clean up to not expose the lifetime - // Safety: we only expose the partition through an outer reference - let mut local_partition: MpiLocalPartition<'static, R> = - unsafe { std::mem::transmute(local_partition) }; let local_result = inner(&mut local_partition, args); diff --git a/necsim/partitioning/mpi/src/partition/mod.rs b/necsim/partitioning/mpi/src/partition/mod.rs index 4561b1a15..a762d94ee 100644 --- a/necsim/partitioning/mpi/src/partition/mod.rs +++ b/necsim/partitioning/mpi/src/partition/mod.rs @@ -30,7 +30,7 @@ pub enum MpiLocalPartition<'p, R: Reporter> { Parallel(Box>), } -impl<'p, R: Reporter> LocalPartition for MpiLocalPartition<'p, R> { +impl<'p, R: Reporter> LocalPartition<'p, R> for MpiLocalPartition<'p, R> { type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where 'p: 'a, R: 'a; type IsLive = False; type Reporter = Self; @@ -51,7 +51,10 @@ impl<'p, R: Reporter> LocalPartition for MpiLocalPartition<'p, R> { emigrants: &mut E, emigration_mode: MigrationMode, immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a> { + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a, + { match self { Self::Root(partition) => { partition.migrate_individuals(emigrants, emigration_mode, immigration_mode) diff --git a/necsim/partitioning/mpi/src/partition/parallel.rs b/necsim/partitioning/mpi/src/partition/parallel.rs index f0eea8412..68eff9271 100644 --- a/necsim/partitioning/mpi/src/partition/parallel.rs +++ b/necsim/partitioning/mpi/src/partition/parallel.rs @@ -81,7 +81,7 @@ impl<'p, R: Reporter> MpiParallelPartition<'p, R> { } } -impl<'p, R: Reporter> LocalPartition for MpiParallelPartition<'p, R> { +impl<'p, R: Reporter> LocalPartition<'p, R> for MpiParallelPartition<'p, R> { type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where 'p: 'a, R: 'a; type IsLive = False; type Reporter = Self; @@ -99,7 +99,10 @@ impl<'p, R: Reporter> LocalPartition for MpiParallelPartition<'p, R> { emigrants: &mut E, emigration_mode: MigrationMode, immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a> { + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a, + { self.common .migrate_individuals(emigrants, emigration_mode, immigration_mode) } diff --git a/necsim/partitioning/mpi/src/partition/root.rs b/necsim/partitioning/mpi/src/partition/root.rs index e3586c1fd..7153c28ac 100644 --- a/necsim/partitioning/mpi/src/partition/root.rs +++ b/necsim/partitioning/mpi/src/partition/root.rs @@ -82,7 +82,7 @@ impl<'p, R: Reporter> MpiRootPartition<'p, R> { } } -impl<'p, R: Reporter> LocalPartition for MpiRootPartition<'p, R> { +impl<'p, R: Reporter> LocalPartition<'p, R> for MpiRootPartition<'p, R> { type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where 'p: 'a, R: 'a; type IsLive = False; type Reporter = Self; @@ -100,7 +100,10 @@ impl<'p, R: Reporter> LocalPartition for MpiRootPartition<'p, R> { emigrants: &mut E, emigration_mode: MigrationMode, immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a> { + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a, + { self.common .migrate_individuals(emigrants, emigration_mode, immigration_mode) } diff --git a/necsim/partitioning/threads/src/lib.rs b/necsim/partitioning/threads/src/lib.rs index c67b7e4e8..5408a70fe 100644 --- a/necsim/partitioning/threads/src/lib.rs +++ b/necsim/partitioning/threads/src/lib.rs @@ -122,7 +122,7 @@ impl ThreadsPartitioning { impl Partitioning for ThreadsPartitioning { type Auxiliary = Option; type FinalisableReporter = FinalisableThreadsReporter; - type LocalPartition = ThreadsLocalPartition; + type LocalPartition<'p, R: Reporter> = ThreadsLocalPartition; fn get_size(&self) -> PartitionSize { self.num_threads @@ -144,7 +144,7 @@ impl Partitioning for ThreadsPartitioning { reporter_context: P, event_log: Self::Auxiliary, args: A, - inner: fn(&mut Self::LocalPartition, A) -> Q, + inner: for<'p> fn(&'p mut Self::LocalPartition<'p, R>, A) -> Q, fold: fn(Q, Q) -> Q, ) -> anyhow::Result<(Q, Self::FinalisableReporter)> { // TODO: add support for multithread live reporting diff --git a/necsim/partitioning/threads/src/partition.rs b/necsim/partitioning/threads/src/partition.rs index 7995e146e..386b16d28 100644 --- a/necsim/partitioning/threads/src/partition.rs +++ b/necsim/partitioning/threads/src/partition.rs @@ -105,8 +105,8 @@ impl ThreadsLocalPartition { } } -impl LocalPartition for ThreadsLocalPartition { - type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where R: 'a; +impl<'p, R: Reporter> LocalPartition<'p, R> for ThreadsLocalPartition { + type ImmigrantIterator<'a> = ImmigrantPopIterator<'a> where 'p: 'a, R: 'a; type IsLive = False; type Reporter = Self; @@ -123,7 +123,10 @@ impl LocalPartition for ThreadsLocalPartition { emigrants: &mut E, emigration_mode: MigrationMode, immigration_mode: MigrationMode, - ) -> Self::ImmigrantIterator<'a> { + ) -> Self::ImmigrantIterator<'a> + where + 'p: 'a, + { for (partition, emigrant) in emigrants { self.emigration_buffers[partition as usize].push(emigrant); } diff --git a/rustcoalescence/algorithms/cuda/src/launch.rs b/rustcoalescence/algorithms/cuda/src/launch.rs index b41adb591..921da4fc3 100644 --- a/rustcoalescence/algorithms/cuda/src/launch.rs +++ b/rustcoalescence/algorithms/cuda/src/launch.rs @@ -50,11 +50,12 @@ use crate::{ #[allow(clippy::too_many_lines)] pub fn initialise_and_simulate< + 'p, M: MathsCore + Sync, G: PrimeableRng + RustToCuda + Sync, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, I: Iterator, L: CudaLineageStoreSampleInitialiser, Error: From, diff --git a/rustcoalescence/algorithms/cuda/src/lib.rs b/rustcoalescence/algorithms/cuda/src/lib.rs index d6cee311a..c19913634 100644 --- a/rustcoalescence/algorithms/cuda/src/lib.rs +++ b/rustcoalescence/algorithms/cuda/src/lib.rs @@ -258,7 +258,7 @@ where >, >, { - type Algorithm> = Self; + type Algorithm<'p, P: LocalPartition<'p, R>> = Self; fn get_logical_partition_size( args: &Self::Arguments, @@ -275,12 +275,13 @@ where } impl< + 'p, M: MathsCore + Sync, G: PrimeableRng + RustToCuda + Sync, O: Scenario, R: Reporter, - P: LocalPartition, - > Algorithm for CudaAlgorithm + P: LocalPartition<'p, R>, + > Algorithm<'p, M, G, O, R, P> for CudaAlgorithm where O::Habitat: RustToCuda + Sync, O::DispersalSampler: RustToCuda + Sync, diff --git a/rustcoalescence/algorithms/cuda/src/parallelisation/monolithic.rs b/rustcoalescence/algorithms/cuda/src/parallelisation/monolithic.rs index 40fca7c02..b049d3d9d 100644 --- a/rustcoalescence/algorithms/cuda/src/parallelisation/monolithic.rs +++ b/rustcoalescence/algorithms/cuda/src/parallelisation/monolithic.rs @@ -45,6 +45,8 @@ type Result = std::result::Result; #[allow(clippy::type_complexity, clippy::too_many_lines)] pub fn simulate< + 'l, + 'p, M: MathsCore + Sync, H: Habitat + RustToCuda + Sync, G: PrimeableRng + RustToCuda + Sync, @@ -58,7 +60,7 @@ pub fn simulate< I: ImmigrationEntry + RustToCuda + Sync, A: SingularActiveLineageSampler + RustToCuda + Sync, P: Reporter, - L: LocalPartition

, + L: LocalPartition<'p, P>, LI: IntoIterator, >( simulation: &mut Simulation, @@ -82,7 +84,7 @@ pub fn simulate< lineages: LI, event_slice: EventSlice, pause_before: Option, - local_partition: &mut L, + local_partition: &'l mut L, ) -> Result<( Status, NonNegativeF64, diff --git a/rustcoalescence/algorithms/gillespie/src/arguments.rs b/rustcoalescence/algorithms/gillespie/src/arguments.rs index 82134aea9..910d03f04 100644 --- a/rustcoalescence/algorithms/gillespie/src/arguments.rs +++ b/rustcoalescence/algorithms/gillespie/src/arguments.rs @@ -117,7 +117,7 @@ pub fn get_gillespie_logical_partition_size( } #[must_use] -pub fn get_gillespie_logical_partition>( +pub fn get_gillespie_logical_partition<'p, R: Reporter, P: LocalPartition<'p, R>>( args: &GillespieArguments, local_partition: &P, ) -> Partition { diff --git a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/fixup.rs b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/fixup.rs index 39fd1b239..7a440732f 100644 --- a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/fixup.rs +++ b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/fixup.rs @@ -105,12 +105,13 @@ where fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: GloballyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/genesis.rs b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/genesis.rs index 27ac0ec69..790ed2bfc 100644 --- a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/genesis.rs +++ b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/genesis.rs @@ -56,12 +56,13 @@ where fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: GloballyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/mod.rs b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/mod.rs index be13d3387..70490f920 100644 --- a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/mod.rs +++ b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/mod.rs @@ -59,12 +59,13 @@ pub trait EventSkippingLineageStoreSampleInitialiser< #[allow(clippy::type_complexity)] fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: GloballyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/resume.rs b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/resume.rs index dc2797935..9f8e10694 100644 --- a/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/resume.rs +++ b/rustcoalescence/algorithms/gillespie/src/event_skipping/initialiser/resume.rs @@ -62,12 +62,13 @@ where fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: GloballyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/event_skipping/launch.rs b/rustcoalescence/algorithms/gillespie/src/event_skipping/launch.rs index 6a970c982..8e92f15b0 100644 --- a/rustcoalescence/algorithms/gillespie/src/event_skipping/launch.rs +++ b/rustcoalescence/algorithms/gillespie/src/event_skipping/launch.rs @@ -34,11 +34,12 @@ use crate::arguments::{ #[allow(clippy::shadow_unrelated, clippy::too_many_lines)] pub fn initialise_and_simulate< + 'p, M: MathsCore, G: SplittableRng, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, I: Iterator, L: EventSkippingLineageStoreSampleInitialiser, Error, diff --git a/rustcoalescence/algorithms/gillespie/src/event_skipping/mod.rs b/rustcoalescence/algorithms/gillespie/src/event_skipping/mod.rs index bd9cc8290..b8f68c957 100644 --- a/rustcoalescence/algorithms/gillespie/src/event_skipping/mod.rs +++ b/rustcoalescence/algorithms/gillespie/src/event_skipping/mod.rs @@ -53,7 +53,7 @@ where GloballyCoherentLineageStore, O::DispersalSampler: SeparableDispersalSampler, { - type Algorithm> = Self; + type Algorithm<'p, P: LocalPartition<'p, R>> = Self; fn get_logical_partition_size( args: &Self::Arguments, @@ -63,8 +63,14 @@ where } } -impl, R: Reporter, P: LocalPartition, M: MathsCore, G: SplittableRng> - Algorithm for EventSkippingAlgorithm +impl< + 'p, + O: Scenario, + R: Reporter, + P: LocalPartition<'p, R>, + M: MathsCore, + G: SplittableRng, + > Algorithm<'p, M, G, O, R, P> for EventSkippingAlgorithm where O::LineageStore>: GloballyCoherentLineageStore, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/fixup.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/fixup.rs index 833e1b2c4..1ac923fd0 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/fixup.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/fixup.rs @@ -90,12 +90,13 @@ impl, M: MathsCore, G: RngCore, O: Scena fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/genesis.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/genesis.rs index 51b885937..4b64fb6e0 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/genesis.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/genesis.rs @@ -37,12 +37,13 @@ impl, O: Scenario> fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/mod.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/mod.rs index 83becf20e..1f2ea44cf 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/mod.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/mod.rs @@ -59,12 +59,13 @@ pub trait ClassicalLineageStoreSampleInitialiser< #[allow(clippy::type_complexity)] fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/resume.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/resume.rs index 34b49dda0..42002b0ba 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/resume.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/initialiser/resume.rs @@ -43,12 +43,13 @@ impl, M: MathsCore, G: RngCore, O: Scena fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/launch.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/launch.rs index b53b2882f..750102da6 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/launch.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/launch.rs @@ -34,11 +34,12 @@ use super::initialiser::ClassicalLineageStoreSampleInitialiser; #[allow(clippy::too_many_lines)] pub fn initialise_and_simulate< + 'p, M: MathsCore, G: SplittableRng, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, I: Iterator, L: ClassicalLineageStoreSampleInitialiser, Error, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/mod.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/mod.rs index 691c7af5b..8fdbd0aa9 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/classical/mod.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/classical/mod.rs @@ -29,12 +29,13 @@ use initialiser::{ // Optimised 'Classical' implementation for the `UniformTurnoverSampler` impl< + 'p, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, M: MathsCore, G: SplittableRng, - > Algorithm for GillespieAlgorithm + > Algorithm<'p, M, G, O, R, P> for GillespieAlgorithm where O::LineageStore>: LocallyCoherentLineageStore, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/mod.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/mod.rs index ed7dcc724..4a9f6c08c 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/mod.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/mod.rs @@ -36,7 +36,7 @@ where O::LineageStore>: LocallyCoherentLineageStore, { - type Algorithm> = Self; + type Algorithm<'p, P: LocalPartition<'p, R>> = Self; fn get_logical_partition_size( args: &Self::Arguments, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/fixup.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/fixup.rs index a2ded2e9f..5483b1567 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/fixup.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/fixup.rs @@ -95,6 +95,7 @@ impl, M: MathsCore, G: RngCore, O: Scena fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, @@ -112,7 +113,7 @@ impl, M: MathsCore, G: RngCore, O: Scena >, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/genesis.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/genesis.rs index 28a29ffae..7e111a418 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/genesis.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/genesis.rs @@ -55,6 +55,7 @@ impl, O: Scenario> fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, @@ -72,7 +73,7 @@ impl, O: Scenario> >, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/mod.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/mod.rs index 767a01580..4def88e33 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/mod.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/mod.rs @@ -47,6 +47,7 @@ pub trait GillespieLineageStoreSampleInitialiser< #[allow(clippy::type_complexity)] fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, @@ -64,7 +65,7 @@ pub trait GillespieLineageStoreSampleInitialiser< >, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/resume.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/resume.rs index 868fecfa4..596c69bb2 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/resume.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/initialiser/resume.rs @@ -61,6 +61,7 @@ impl, M: MathsCore, G: RngCore, O: Scena fn init< 'h, + 'p, T: TrustedOriginSampler<'h, M, Habitat = O::Habitat>, S: LocallyCoherentLineageStore, X: EmigrationExit, @@ -78,7 +79,7 @@ impl, M: MathsCore, G: RngCore, O: Scena >, I: ImmigrationEntry, Q: Reporter, - P: LocalPartition, + P: LocalPartition<'p, Q>, >( self, origin_sampler: T, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/launch.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/launch.rs index 91a49c346..e34dbe25f 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/launch.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/launch.rs @@ -33,11 +33,12 @@ use super::initialiser::GillespieLineageStoreSampleInitialiser; #[allow(clippy::shadow_unrelated, clippy::too_many_lines)] pub fn initialise_and_simulate< + 'p, M: MathsCore, G: SplittableRng, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, I: Iterator, L: GillespieLineageStoreSampleInitialiser, Error, diff --git a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/mod.rs b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/mod.rs index 0741a1e0c..4c307d4e7 100644 --- a/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/mod.rs +++ b/rustcoalescence/algorithms/gillespie/src/gillespie/turnover/mod.rs @@ -30,8 +30,14 @@ use initialiser::{ }; // Default 'Gillespie' implementation for any turnover sampler -impl, R: Reporter, P: LocalPartition, M: MathsCore, G: SplittableRng> - Algorithm for GillespieAlgorithm +impl< + 'p, + O: Scenario, + R: Reporter, + P: LocalPartition<'p, R>, + M: MathsCore, + G: SplittableRng, + > Algorithm<'p, M, G, O, R, P> for GillespieAlgorithm where O::LineageStore>: LocallyCoherentLineageStore, diff --git a/rustcoalescence/algorithms/independent/src/launch.rs b/rustcoalescence/algorithms/independent/src/launch.rs index 2eab23e40..bc645a6dd 100644 --- a/rustcoalescence/algorithms/independent/src/launch.rs +++ b/rustcoalescence/algorithms/independent/src/launch.rs @@ -43,11 +43,12 @@ use crate::{ #[allow(clippy::too_many_lines)] pub fn initialise_and_simulate< + 'p, M: MathsCore, G: PrimeableRng, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, I: Iterator, L: IndependentLineageStoreSampleInitialiser, Error, diff --git a/rustcoalescence/algorithms/independent/src/lib.rs b/rustcoalescence/algorithms/independent/src/lib.rs index 8a01eef95..026d1f1e5 100644 --- a/rustcoalescence/algorithms/independent/src/lib.rs +++ b/rustcoalescence/algorithms/independent/src/lib.rs @@ -52,7 +52,7 @@ impl AlgorithmDefaults for IndependentAlgorithm { impl, O: Scenario, R: Reporter> AlgorithmDispatch for IndependentAlgorithm { - type Algorithm> = Self; + type Algorithm<'p, P: LocalPartition<'p, R>> = Self; fn get_logical_partition_size( args: &Self::Arguments, @@ -71,8 +71,14 @@ impl, O: Scenario, R: Reporter> Algorithm } } -impl, R: Reporter, P: LocalPartition, M: MathsCore, G: PrimeableRng> - Algorithm for IndependentAlgorithm +impl< + 'p, + O: Scenario, + R: Reporter, + P: LocalPartition<'p, R>, + M: MathsCore, + G: PrimeableRng, + > Algorithm<'p, M, G, O, R, P> for IndependentAlgorithm { type LineageStore = IndependentLineageStore; diff --git a/rustcoalescence/algorithms/src/lib.rs b/rustcoalescence/algorithms/src/lib.rs index 114bb9915..b668ee5e9 100644 --- a/rustcoalescence/algorithms/src/lib.rs +++ b/rustcoalescence/algorithms/src/lib.rs @@ -36,7 +36,15 @@ pub trait AlgorithmDefaults { pub trait AlgorithmDispatch, O: Scenario, R: Reporter>: AlgorithmParamters + AlgorithmDefaults { - type Algorithm>: Algorithm; + type Algorithm<'p, P: LocalPartition<'p, R>>: Algorithm< + 'p, + M, + G, + O, + R, + P, + Arguments = Self::Arguments, + >; fn get_logical_partition_size( args: &Self::Arguments, @@ -45,11 +53,12 @@ pub trait AlgorithmDispatch, O: Scenario, R: R } pub trait Algorithm< + 'p, M: MathsCore, G: RngCore, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, >: Sized + AlgorithmParamters + AlgorithmDefaults + AlgorithmDispatch { type LineageStore: LineageStore; diff --git a/rustcoalescence/src/cli/simulate/dispatch/valid/launch.rs b/rustcoalescence/src/cli/simulate/dispatch/valid/launch.rs index 9e30290d2..8b1978ee3 100644 --- a/rustcoalescence/src/cli/simulate/dispatch/valid/launch.rs +++ b/rustcoalescence/src/cli/simulate/dispatch/valid/launch.rs @@ -15,12 +15,13 @@ use rustcoalescence_scenarios::{Scenario, ScenarioCogs}; use crate::args::config::sample::{Sample, SampleMode, SampleModeRestart, SampleOrigin}; pub(super) fn simulate< + 'p, M: MathsCore, G: RngCore, - A: Algorithm, + A: Algorithm<'p, M, G, O, R, P>, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, >( local_partition: &mut P, diff --git a/rustcoalescence/src/cli/simulate/dispatch/valid/partitioning.rs b/rustcoalescence/src/cli/simulate/dispatch/valid/partitioning.rs index 72b52433b..2d47aff09 100644 --- a/rustcoalescence/src/cli/simulate/dispatch/valid/partitioning.rs +++ b/rustcoalescence/src/cli/simulate/dispatch/valid/partitioning.rs @@ -52,7 +52,7 @@ where args, |partition, (sample, rng, scenario, algorithm_args, pause_before)| match partition { MonolithicLocalPartition::Live(partition) => { - wrap::, O, R, _>( + wrap::, O, R, _>( &mut **partition, sample, rng, @@ -62,7 +62,7 @@ where ) }, MonolithicLocalPartition::Recorded(partition) => { - wrap::, O, R, _>( + wrap::, O, R, _>( &mut **partition, sample, rng, @@ -87,16 +87,18 @@ where event_log, args, |partition, (sample, rng, scenario, algorithm_args, pause_before)| match partition { - MpiLocalPartition::Root(partition) => wrap::, O, R, _>( - &mut **partition, - sample, - rng, - scenario, - algorithm_args, - pause_before, - ), + MpiLocalPartition::Root(partition) => { + wrap::, O, R, _>( + &mut **partition, + sample, + rng, + scenario, + algorithm_args, + pause_before, + ) + }, MpiLocalPartition::Parallel(partition) => { - wrap::, O, R, _>( + wrap::, O, R, _>( &mut **partition, sample, rng, @@ -116,7 +118,7 @@ where event_log, args, |partition, (sample, rng, scenario, algorithm_args, pause_before)| { - wrap::, O, R, _>( + wrap::, O, R, _>( partition, sample, rng, @@ -133,12 +135,13 @@ where } fn wrap< + 'p, M: MathsCore, G: RngCore, - A: Algorithm, + A: Algorithm<'p, M, G, O, R, P>, O: Scenario, R: Reporter, - P: LocalPartition, + P: LocalPartition<'p, R>, >( local_partition: &mut P, @@ -151,7 +154,7 @@ fn wrap< where Result, A::Error>: anyhow::Context, A::Error>, { - launch::simulate::, O, R, _>( + launch::simulate::, O, R, _>( local_partition, sample, rng,