Skip to content

Commit

Permalink
Extensive local partition lifetime refactoring ... not yet sure if it…
Browse files Browse the repository at this point in the history
…'s worth it
  • Loading branch information
juntyr committed Jun 1, 2024
1 parent f2c632c commit aa36dc9
Show file tree
Hide file tree
Showing 64 changed files with 455 additions and 489 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"rust-analyzer.cargo.features": [
"all-algorithms",
"all-scenarios",
"mpi-partitioning"
"all-partitionings",
],
}
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use super::{reporter::IgnoreProgressReporterProxy, DedupCache};

#[allow(clippy::type_complexity)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
G: PrimeableRng<M>,
Expand All @@ -57,7 +56,7 @@ pub fn simulate<
NeverImmigrationEntry,
>,
R: Reporter,
P: LocalPartition<'p, R>,
P: LocalPartition<R>,
L: IntoIterator<Item = Lineage>,
>(
simulation: &mut Simulation<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use super::{reporter::IgnoreProgressReporterProxy, DedupCache};

#[allow(clippy::type_complexity, clippy::too_many_lines)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
C: Decomposition<M, H>,
Expand All @@ -62,7 +61,7 @@ pub fn simulate<
NeverImmigrationEntry,
>,
R: Reporter,
P: LocalPartition<'p, R>,
P: LocalPartition<R>,
L: IntoIterator<Item = Lineage>,
>(
simulation: &mut Simulation<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use reporter::{

#[allow(clippy::type_complexity, clippy::too_many_lines)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
G: PrimeableRng<M>,
Expand All @@ -62,7 +61,7 @@ pub fn simulate<
NeverImmigrationEntry,
>,
R: Reporter,
P: LocalPartition<'p, R>,
P: LocalPartition<R>,
L: IntoIterator<Item = Lineage>,
>(
simulation: &mut Simulation<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ use necsim_partitioning_core::LocalPartition;
use super::WaterLevelReporterProxy;

#[allow(clippy::module_name_repetitions)]
pub struct LiveWaterLevelReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> {
pub struct LiveWaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition<R>> {
water_level: NonNegativeF64,
slow_events: Vec<PackedEvent>,
fast_events: Vec<PackedEvent>,

local_partition: &'l mut P,
_marker: PhantomData<(&'p (), R)>,
local_partition: &'p mut P,
_marker: PhantomData<R>,
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug
for LiveWaterLevelReporterProxy<'l, 'p, R, P>
{
impl<'p, R: Reporter, P: LocalPartition<R>> fmt::Debug for LiveWaterLevelReporterProxy<'p, R, P> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
struct EventBufferLen(usize);

Expand All @@ -42,9 +40,7 @@ impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug
}
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter
for LiveWaterLevelReporterProxy<'l, 'p, R, P>
{
impl<'p, R: Reporter, P: LocalPartition<R>> Reporter for LiveWaterLevelReporterProxy<'p, R, P> {
impl_report!(speciation(&mut self, speciation: MaybeUsed<R::ReportSpeciation>) {
if speciation.event_time < self.water_level {
self.slow_events.push(speciation.clone().into());
Expand All @@ -65,10 +61,10 @@ impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter
}

#[contract_trait]
impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> WaterLevelReporterProxy<'l, 'p, R, P>
for LiveWaterLevelReporterProxy<'l, 'p, R, P>
impl<'p, R: Reporter, P: LocalPartition<R>> WaterLevelReporterProxy<'p, R, P>
for LiveWaterLevelReporterProxy<'p, R, P>
{
fn new(capacity: usize, local_partition: &'l mut P) -> Self {
fn new(capacity: usize, local_partition: &'p mut P) -> Self {
info!("Events will be reported using the live water-level algorithm ...");

Self {
Expand All @@ -77,7 +73,7 @@ impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> WaterLevelReporterProxy<'l,
fast_events: Vec::with_capacity(capacity),

local_partition,
_marker: PhantomData::<(&'p (), R)>,
_marker: PhantomData::<R>,
}
}

Expand Down Expand Up @@ -119,9 +115,7 @@ impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> WaterLevelReporterProxy<'l,
}
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Drop
for LiveWaterLevelReporterProxy<'l, 'p, R, P>
{
impl<'p, R: Reporter, P: LocalPartition<R>> Drop for LiveWaterLevelReporterProxy<'p, R, P> {
fn drop(&mut self) {
// Report all events below the water level in sorted order
self.slow_events.sort_unstable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ mod recorded;
#[allow(clippy::inline_always, clippy::inline_fn_without_body)]
#[allow(clippy::no_effect_underscore_binding)]
#[contract_trait]
pub trait WaterLevelReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>>:
pub trait WaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition<R>>:
Sized
+ Reporter<
ReportSpeciation = R::ReportSpeciation,
ReportDispersal = R::ReportDispersal,
ReportProgress = False,
>
{
fn new(capacity: usize, local_partition: &'l mut P) -> Self;
fn new(capacity: usize, local_partition: &'p mut P) -> Self;

fn water_level(&self) -> NonNegativeF64;

Expand All @@ -36,24 +36,23 @@ pub trait WaterLevelReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>>
pub enum WaterLevelReporterStrategy {}

pub trait WaterLevelReporterConstructor<
'l,
'p,
IsLive: Boolean,
R: Reporter,
P: 'l + LocalPartition<'p, R, IsLive = IsLive>,
P: 'p + LocalPartition<R, IsLive = IsLive>,
>
{
type WaterLevelReporter: WaterLevelReporterProxy<'l, 'p, R, P>;
type WaterLevelReporter: WaterLevelReporterProxy<'p, R, P>;
}

impl<'l, 'p, IsLive: Boolean, R: Reporter, P: 'l + LocalPartition<'p, R, IsLive = IsLive>>
WaterLevelReporterConstructor<'l, 'p, IsLive, R, P> for WaterLevelReporterStrategy
impl<'p, IsLive: Boolean, R: Reporter, P: 'p + LocalPartition<R, IsLive = IsLive>>
WaterLevelReporterConstructor<'p, IsLive, R, P> for WaterLevelReporterStrategy
{
default type WaterLevelReporter = live::LiveWaterLevelReporterProxy<'l, 'p, R, P>;
default type WaterLevelReporter = live::LiveWaterLevelReporterProxy<'p, R, P>;
}

impl<'l, 'p, R: Reporter, P: 'l + LocalPartition<'p, R, IsLive = False>>
WaterLevelReporterConstructor<'l, 'p, False, R, P> for WaterLevelReporterStrategy
impl<'p, R: Reporter, P: 'p + LocalPartition<R, IsLive = False>>
WaterLevelReporterConstructor<'p, False, R, P> for WaterLevelReporterStrategy
{
type WaterLevelReporter = recorded::RecordedWaterLevelReporterProxy<'l, 'p, R, P>;
type WaterLevelReporter = recorded::RecordedWaterLevelReporterProxy<'p, R, P>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use necsim_partitioning_core::LocalPartition;
use super::WaterLevelReporterProxy;

#[allow(clippy::module_name_repetitions)]
pub struct RecordedWaterLevelReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> {
pub struct RecordedWaterLevelReporterProxy<'p, R: Reporter, P: LocalPartition<R>> {
water_level: NonNegativeF64,

local_partition: &'l mut P,
_marker: PhantomData<(&'p (), R)>,
local_partition: &'p mut P,
_marker: PhantomData<R>,
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug
for RecordedWaterLevelReporterProxy<'l, 'p, R, P>
impl<'p, R: Reporter, P: LocalPartition<R>> fmt::Debug
for RecordedWaterLevelReporterProxy<'p, R, P>
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct(stringify!(RecordedWaterLevelReporterProxy))
Expand All @@ -25,9 +25,7 @@ impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug
}
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter
for RecordedWaterLevelReporterProxy<'l, 'p, R, P>
{
impl<'p, R: Reporter, P: LocalPartition<R>> Reporter for RecordedWaterLevelReporterProxy<'p, R, P> {
impl_report!(speciation(&mut self, speciation: MaybeUsed<R::ReportSpeciation>) {
self.local_partition.get_reporter().report_speciation(speciation.into());
});
Expand All @@ -40,17 +38,17 @@ impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter
}

#[contract_trait]
impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> WaterLevelReporterProxy<'l, 'p, R, P>
for RecordedWaterLevelReporterProxy<'l, 'p, R, P>
impl<'p, R: Reporter, P: LocalPartition<R>> WaterLevelReporterProxy<'p, R, P>
for RecordedWaterLevelReporterProxy<'p, R, P>
{
fn new(_capacity: usize, local_partition: &'l mut P) -> Self {
fn new(_capacity: usize, local_partition: &'p mut P) -> Self {
info!("Events will be reported using the recorded water-level algorithm ...");

Self {
water_level: NonNegativeF64::zero(),

local_partition,
_marker: PhantomData::<(&'p (), R)>,
_marker: PhantomData::<R>,
}
}

Expand Down
24 changes: 10 additions & 14 deletions necsim/impls/no-std/src/parallelisation/independent/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,39 @@ use necsim_core::{impl_report, reporter::Reporter};

use necsim_partitioning_core::LocalPartition;

pub struct IgnoreProgressReporterProxy<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> {
local_partition: &'l mut P,
_marker: PhantomData<(&'p (), R)>,
pub struct IgnoreProgressReporterProxy<'p, R: Reporter, P: LocalPartition<R>> {
local_partition: &'p mut P,
_marker: PhantomData<R>,
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> fmt::Debug
for IgnoreProgressReporterProxy<'l, 'p, R, P>
{
impl<'p, R: Reporter, P: LocalPartition<R>> fmt::Debug for IgnoreProgressReporterProxy<'p, R, P> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct(stringify!(IgnoreProgressReporterProxy))
.finish()
}
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> Reporter
for IgnoreProgressReporterProxy<'l, 'p, R, P>
{
impl<'p, R: Reporter, P: LocalPartition<R>> Reporter for IgnoreProgressReporterProxy<'p, R, P> {
impl_report!(speciation(&mut self, speciation: MaybeUsed<
<<P as LocalPartition<'p, R>>::Reporter as Reporter
<<P as LocalPartition<R>>::Reporter as Reporter
>::ReportSpeciation>) {
self.local_partition.get_reporter().report_speciation(speciation.into());
});

impl_report!(dispersal(&mut self, dispersal: MaybeUsed<
<<P as LocalPartition<'p, R>>::Reporter as Reporter
<<P as LocalPartition<R>>::Reporter as Reporter
>::ReportDispersal>) {
self.local_partition.get_reporter().report_dispersal(dispersal.into());
});

impl_report!(progress(&mut self, _progress: Ignored) {});
}

impl<'l, 'p, R: Reporter, P: LocalPartition<'p, R>> IgnoreProgressReporterProxy<'l, 'p, R, P> {
pub fn from(local_partition: &'l mut P) -> Self {
impl<'p, R: Reporter, P: LocalPartition<R>> IgnoreProgressReporterProxy<'p, R, P> {
pub fn from(local_partition: &'p mut P) -> Self {
Self {
local_partition,
_marker: PhantomData::<(&'p (), R)>,
_marker: PhantomData::<R>,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::{

#[allow(clippy::type_complexity)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
G: RngCore<M>,
Expand All @@ -48,7 +47,7 @@ pub fn simulate<
BufferedImmigrationEntry,
>,
P: Reporter,
L: LocalPartition<'p, P>,
L: LocalPartition<P>,
>(
simulation: &mut Simulation<
M,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::{

#[allow(clippy::type_complexity)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
G: RngCore<M>,
Expand All @@ -48,7 +47,7 @@ pub fn simulate<
BufferedImmigrationEntry,
>,
P: Reporter,
L: LocalPartition<'p, P>,
L: LocalPartition<P>,
>(
simulation: &mut Simulation<
M,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use crate::{

#[allow(clippy::type_complexity)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
G: RngCore<M>,
Expand All @@ -34,7 +33,7 @@ pub fn simulate<
E: EventSampler<M, H, G, S, NeverEmigrationExit, D, C, T, N>,
A: ActiveLineageSampler<M, H, G, S, NeverEmigrationExit, D, C, T, N, E, NeverImmigrationEntry>,
P: Reporter,
L: LocalPartition<'p, P>,
L: LocalPartition<P>,
>(
simulation: &mut Simulation<
M,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use super::reporter::BufferingReporterProxy;

#[allow(clippy::type_complexity)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
G: RngCore<M>,
Expand All @@ -53,7 +52,7 @@ pub fn simulate<
BufferedImmigrationEntry,
>,
P: Reporter,
L: LocalPartition<'p, P>,
L: LocalPartition<P>,
>(
simulation: &mut Simulation<
M,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use crate::{

#[allow(clippy::type_complexity)]
pub fn simulate<
'p,
M: MathsCore,
H: Habitat<M>,
G: RngCore<M>,
Expand All @@ -48,7 +47,7 @@ pub fn simulate<
BufferedImmigrationEntry,
>,
P: Reporter,
L: LocalPartition<'p, P>,
L: LocalPartition<P>,
>(
simulation: &mut Simulation<
M,
Expand Down
Loading

0 comments on commit aa36dc9

Please sign in to comment.