20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
mod worker;
pub use worker::Worker;
mod msg;
pub use crate::mpi::problem::DistributedFirstOrderProblem;
use either::Either;
use log::debug;
use mpi::traits::*;
use mpi::Threading;
use serde::Serialize;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("mpi initialization could not create a universe.")]
NoUniverse,
}
/// Create a first order problem for usage with MPI.
///
/// The function returns either [`Problem`] or a [`Worker`] depending
/// on whether the current task is being run on the root node or some
/// worker node.
pub fn new_problem<P: DistributedFirstOrderProblem>(problem: P) -> Result<Either<Problem<P>, Worker<P>>, Error>
where
P::Minorant: Serialize,
P::Err: Serialize,
{
let (universe, thr) = mpi::initialize_with_threading(Threading::Multiple).ok_or(Error::NoUniverse)?;
let world = universe.world();
let rank = world.rank();
debug!(
"Init universe [{}]: {:?} {:?}",
rank,
thr,
mpi::environment::threading_support()
);
if rank == 0 {
// root node, the main process
Ok(Either::Left(Problem::new(universe, problem)))
} else {
Ok(Either::Right(Worker::new(universe, problem)))
}
}
|
<
>
>
>
>
>
>
|
|
|
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
mod worker;
pub use worker::Worker;
mod msg;
pub use crate::mpi::problem::DistributedFirstOrderProblem;
use log::debug;
use mpi::traits::*;
use mpi::Threading;
use serde::Serialize;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("mpi initialization could not create a universe.")]
NoUniverse,
}
/// An MPI task, either the main process or a worker process.
pub enum Task<P: DistributedFirstOrderProblem + 'static> {
Main(Problem<P>),
Worker(Worker<P>),
}
/// Create a first order problem for usage with MPI.
///
/// The function returns either [`Problem`] or a [`Worker`] depending
/// on whether the current task is being run on the root node or some
/// worker node.
pub fn new_problem<P: DistributedFirstOrderProblem>(problem: P) -> Result<Task<P>, Error>
where
P::Minorant: Serialize,
P::Err: Serialize,
{
let (universe, thr) = mpi::initialize_with_threading(Threading::Multiple).ok_or(Error::NoUniverse)?;
let world = universe.world();
let rank = world.rank();
debug!(
"Init universe [{}]: {:?} {:?}",
rank,
thr,
mpi::environment::threading_support()
);
if rank == 0 {
// root node, the main process
Ok(Task::Main(Problem::new(universe, problem)))
} else {
Ok(Task::Worker(Worker::new(universe, problem)))
}
}
|