Skip to content

Commit

Permalink
Integrate threads partitioning with rustcoalescence
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed May 26, 2024
1 parent 74a85f5 commit 84d133c
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ necsim-rust consists of the following crates:
- core/: `necsim-partitioning-core` declares the core partitioning traits
- monolithic/: `necsim-partitioning-monolithic` implements monolithic, i.e. non-parallel partitioning
- mpi/: `necsim-partitioning-mpi` implements the MPI-based partitioning backend
- threads/: `necsim-partitioning-threads` implements the multithreading partitioning backend
- rustcoalescence/: `rustcoalescence` provides the command-line interface.
- scenarios/: `rustcoalescence-scenarios` contains the glue code to put together the cogs for the built-in scenarios. It is specifically built only for reducing code duplication in rustcoalescence, not for giving a minimal example of how to construct a simulation.
- algorithms/:
Expand Down
13 changes: 13 additions & 0 deletions docs/simulate.ron
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,19 @@
* optional, default = "100ms" */
progress: (DurationString),
)
/* the simulation is divided up across multiple threads
* multi-threaded, single-process
* requires the `threads-partitioning` feature */
| Threads(
/* number of threads to distribute the simulation across */
threads: (1 < u32),
/* minimum time interval between migration messages
* optional, default = "100ms" */
migration: (DurationString),
/* minimum time interval between progress messages
* optional, default = "100ms" */
progress: (DurationString),
)
),

/* selection of the event persistence strategy
Expand Down
7 changes: 7 additions & 0 deletions rustcoalescence/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ all-scenarios = [
]

mpi-partitioning = ["dep:necsim-partitioning-mpi"]
threads-partitioning = ["dep:necsim-partitioning-threads"]

all-partitioning = [
"mpi-partitioning",
"threads-partitioning",
]

[dependencies]
necsim-core = { path = "../necsim/core" }
Expand All @@ -70,6 +76,7 @@ rustcoalescence-scenarios = { path = "scenarios" }
rustcoalescence-algorithms = { path = "algorithms" }

necsim-partitioning-mpi = { path = "../necsim/partitioning/mpi", optional = true }
necsim-partitioning-threads = { path = "../necsim/partitioning/threads", optional = true }

rustcoalescence-algorithms-gillespie = { path = "algorithms/gillespie", optional = true }
rustcoalescence-algorithms-independent = { path = "algorithms/independent", optional = true }
Expand Down
27 changes: 14 additions & 13 deletions rustcoalescence/src/args/config/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,43 @@ use necsim_partitioning_core::partition::PartitionSize;
#[derive(Debug, Serialize, Deserialize)]
pub enum Partitioning {
Monolithic(necsim_partitioning_monolithic::MonolithicPartitioning),
#[cfg(feature = "necsim-partitioning-mpi")]
#[cfg(feature = "mpi-partitioning")]
#[serde(alias = "MPI")]
Mpi(necsim_partitioning_mpi::MpiPartitioning),
#[cfg(feature = "threads-partitioning")]
Threads(necsim_partitioning_threads::ThreadsPartitioning),
}

impl Partitioning {
// pub fn is_root(&self) -> bool {
// use necsim_partitioning_core::Partitioning;

// match self {
// Self::Monolithic(partitioning) => partitioning.is_root(),
// #[cfg(feature = "necsim-partitioning-mpi")]
// Self::Mpi(partitioning) => partitioning.is_root(),
// }
// }

pub fn get_size(&self) -> PartitionSize {
use necsim_partitioning_core::Partitioning;

match self {
Self::Monolithic(partitioning) => partitioning.get_size(),
#[cfg(feature = "necsim-partitioning-mpi")]
#[cfg(feature = "mpi-partitioning")]
Self::Mpi(partitioning) => partitioning.get_size(),
#[cfg(feature = "threads-partitioning")]
Self::Threads(partitioning) => partitioning.get_size(),
}
}

pub fn get_event_log_check(&self) -> (anyhow::Result<()>, anyhow::Result<()>) {
match self {
Self::Monolithic(_) => (Ok(()), Ok(())),
#[cfg(feature = "necsim-partitioning-mpi")]
#[cfg(feature = "mpi-partitioning")]
Self::Mpi(_) => (
Err(anyhow::anyhow!(
necsim_partitioning_mpi::MpiLocalPartitionError::MissingEventLog
)),
Ok(()),
),
#[cfg(feature = "threads-partitioning")]
Self::Threads(_) => (
Err(anyhow::anyhow!(
necsim_partitioning_mpi::MpiLocalPartitionError::MissingEventLog
)),
Ok(()),
),
}
}
}
Expand Down
22 changes: 20 additions & 2 deletions rustcoalescence/src/cli/simulate/dispatch/valid/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use necsim_impls_std::event_log::recorder::EventLogRecorder;
use necsim_partitioning_core::{context::ReporterContext, LocalPartition, Partitioning as _};

use necsim_partitioning_monolithic::MonolithicLocalPartition;
#[cfg(feature = "necsim-partitioning-mpi")]
#[cfg(feature = "mpi-partitioning")]
use necsim_partitioning_mpi::MpiLocalPartition;
use rustcoalescence_algorithms::{result::SimulationOutcome, Algorithm, AlgorithmDispatch};
use rustcoalescence_scenarios::Scenario;
Expand Down Expand Up @@ -83,7 +83,7 @@ where
},
fold,
),
#[cfg(feature = "necsim-partitioning-mpi")]
#[cfg(feature = "mpi-partitioning")]
Partitioning::Mpi(partitioning) => partitioning.with_local_partition(
reporter_context,
event_log,
Expand Down Expand Up @@ -116,6 +116,24 @@ where
},
fold,
),
#[cfg(feature = "threads-partitioning")]
Partitioning::Threads(partitioning) => partitioning.with_local_partition(
reporter_context,
event_log,
args,
|partition, (sample, rng, scenario, algorithm_args, pause_before, normalised_args)| {
wrap::<M, G, A::Algorithm<'_, _>, O, R, _>(
partition,
sample,
rng,
scenario,
algorithm_args,
pause_before,
normalised_args,
)
},
fold,
),
}
.and_then(|result| result.map_err(anyhow::Error::msg))
}
Expand Down
8 changes: 6 additions & 2 deletions rustcoalescence/src/cli/simulate/dispatch/valid/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ where
Partitioning::Monolithic(partitioning) => {
A::get_logical_partition_size(&algorithm_args, partitioning)
},
#[cfg(feature = "necsim-partitioning-mpi")]
Partitioning::MPI(partitioning) => {
#[cfg(feature = "mpi-partitioning")]
Partitioning::Mpi(partitioning) => {
A::get_logical_partition_size(&algorithm_args, partitioning)
},
#[cfg(feature = "threads-partitioning")]
Partitioning::Threads(partitioning) => {
A::get_logical_partition_size(&algorithm_args, partitioning)
},
},
Expand Down
2 changes: 1 addition & 1 deletion rustcoalescence/src/cli/simulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn simulate_with_logger(simulate_args: CommandArgs) -> anyhow::Result<()> {

let partitioning = parse::partitioning::parse_and_normalise(&ron_args, &mut normalised_args)?;

#[cfg(feature = "necsim-partitioning-mpi")]
#[cfg(feature = "mpi-partitioning")]
if let crate::args::config::partitioning::Partitioning::Mpi(partitioning) = &partitioning {
// Only log to stdout/stderr in the MPI root partition
if !partitioning.peek_is_root() {
Expand Down

0 comments on commit 84d133c

Please sign in to comment.