/// Run the provided closure on a single process, with all multi-process code factored out
/// into the provided `Dispatch`.
///
/// The closure will receive an object which allows one to invoke the `Dispatch` on demand.
/// This object must not be leaked.
///
/// # MPI
///
/// This method is called on all processes.  The closure is called on the root process,
/// while the others enter an event loop (mostly blocking, waiting for `invoke` to be called).
/// When the closure exits, execution resumes on all processes.
///
/// **Important:** Currently, if a process panics at a bad time, the other processes may
/// get deadlocked on a blocking operation. Nothing is done about this by default.
/// See the helper method `with_mpi_abort_on_unwind` for a possible solution.
///
/// # Panics
///
/// Panics after the function returns if it is detected that the `MpiOnDemand`
/// has been leaked.
Run the provided closure on a single process, with all multi-process code factored out
into the provided `Dispatch`.

The closure will receive an object which allows one to invoke the `Dispatch` on demand.
This object must not be leaked.
Run the provided closure on a single process with all multi - process code factored out into the provided ` Dispatch ` . The closure will receive an object which allows one to invoke the ` Dispatch ` on demand . This object must not be leaked .
pub fn install<R>(
        dispatch: D,
        func: impl FnOnce(MpiOnDemand<D>) -> R,
    ) -> Option<R> {
        let on_demand = MpiOnDemandInner { dispatch };
        // a note to future me (because he's an idiot):
        //
        // The continuation on the next line is entirely incidental and unrelated to the reason why
        // this function takes a continuation. (and that reason is a very good one: to delimit
        // the scope of single-process mode.)
        with_default_root(|root| {
            if this_process_is_root(&root) {
                let on_demand = MpiOnDemand(Arc::new(on_demand));
                let out = func(on_demand.clone());
                Arc::try_unwrap(on_demand.0).ok()
                    .expect("Detected leak of `MpiOnDemand` value!")
                    .root_finish(&root);
                Some(out)
            } else {
                on_demand.non_root_event_loop(&root);
                None
            }
        })
    }
pub fn install < R > ( dispatch : D , func : impl FnOnce ( MpiOnDemand < D > ) -> R , ) -> Option < R > { let on_demand = MpiOnDemandInner { dispatch } ; // a note to future me (because he's an idiot): // // The continuation on the next line is entirely incidental and unrelated to the reason why // this function takes a continuation. (and that reason is a very good one: to delimit // the scope of single-process mode.) with_default_root ( | root | { if this_process_is_root ( & root ) { let on_demand = MpiOnDemand ( Arc :: new ( on_demand ) ) ; let out = func ( on_demand . clone ( ) ) ; Arc :: try_unwrap ( on_demand . 0 ) . ok ( ) . expect ( " " ) . root_finish ( & root ) ; Some ( out ) } else { on_demand . non_root_event_loop ( & root ) ; None } } ) }
Run the provided closure on a single process, with all multi-process code factored out
into the provided `Dispatch`.
Run the provided closure on a single process with all multi - process code factored out into the provided ` Dispatch ` .
dispatch
D
func
impl FnOnce(MpiOnDemand<D>) -> R
mpi
This method is called on all processes.  The closure is called on the root process,
while the others enter an event loop (mostly blocking, waiting for `invoke` to be called).
When the closure exits, execution resumes on all processes.

Currently, if a process panics at a bad time, the other processes may
get deadlocked on a blocking operation. Nothing is done about this by default.
See the helper method `with_mpi_abort_on_unwind` for a possible solution.
This method is called on all processes . The closure is called on the root process while the others enter an event loop ( mostly blocking waiting for ` invoke ` to be called ) . When the closure exits execution resumes on all processes . Currently if a process panics at a bad time the other processes may get deadlocked on a blocking operation . Nothing is done about this by default . See the helper method ` with_mpi_abort_on_unwind ` for a possible solution .
panics
Panics after the function returns if it is detected that the `MpiOnDemand`
has been leaked.
Panics after the function returns if it is detected that the ` MpiOnDemand ` has been leaked .