1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use serde::Deserialize;

use crate::args::{config::partitioning::Partitioning, utils::parse::try_parse};

use super::super::BufferingSimulateArgsBuilder;

pub(in super::super) fn parse_and_normalise(
    ron_args: &str,
    normalised_args: &mut BufferingSimulateArgsBuilder,
) -> anyhow::Result<Partitioning> {
    let SimulateArgsPartitioningOnly { partitioning } = try_parse("simulate", ron_args)?;

    normalised_args.partitioning(&partitioning);

    #[cfg(feature = "mpi-partitioning")]
    if !matches!(&partitioning, Partitioning::Mpi(_)) {
        match necsim_partitioning_mpi::MpiPartitioning::initialise() {
            Ok(_) | Err(necsim_partitioning_mpi::MpiPartitioningError::AlreadyInitialised) => {
                anyhow::bail!("MPI should not be used together with a non-MPI partitioning")
            },
            Err(necsim_partitioning_mpi::MpiPartitioningError::NoParallelism) => (),
        }
    }

    Ok(partitioning)
}

#[derive(Deserialize)]
#[serde(rename = "Simulate")]
struct SimulateArgsPartitioningOnly {
    #[serde(default)]
    partitioning: Partitioning,
}