use crate::progress::{Timestamp, Operate, Source, Target};
use crate::order::Product;
use crate::progress::timestamp::Refines;
use crate::communication::Allocate;
use crate::worker::AsWorker;
pub mod child;
pub use self::child::Child;
pub trait ScopeParent: AsWorker+Clone {
type Timestamp : Timestamp;
}
impl<A: Allocate> ScopeParent for crate::worker::Worker<A> {
type Timestamp = ();
}
pub trait Scope: ScopeParent {
fn name(&self) -> String;
fn addr(&self) -> Vec<usize>;
fn add_edge(&self, source: Source, target: Target);
fn add_operator(&mut self, operator: Box<Operate<Self::Timestamp>>) -> usize {
let index = self.allocate_operator_index();
let global = self.new_identifier();
self.add_operator_with_indices(operator, index, global);
index
}
fn allocate_operator_index(&mut self) -> usize;
fn add_operator_with_index(&mut self, operator: Box<Operate<Self::Timestamp>>, index: usize) {
let global = self.new_identifier();
self.add_operator_with_indices(operator, index, global);
}
fn add_operator_with_indices(&mut self, operator: Box<Operate<Self::Timestamp>>, local: usize, global: usize);
fn scoped<T, R, F>(&mut self, name: &str, func: F) -> R
where
T: Timestamp+Refines<<Self as ScopeParent>::Timestamp>,
F: FnOnce(&mut Child<Self, T>) -> R;
fn iterative<T, R, F>(&mut self, func: F) -> R
where
T: Timestamp,
F: FnOnce(&mut Child<Self, Product<<Self as ScopeParent>::Timestamp, T>>) -> R,
{
self.scoped::<Product<<Self as ScopeParent>::Timestamp, T>,R,F>("Iterative", func)
}
fn region<R, F>(&mut self, func: F) -> R
where
F: FnOnce(&mut Child<Self, <Self as ScopeParent>::Timestamp>) -> R,
{
self.scoped::<<Self as ScopeParent>::Timestamp,R,F>("Region", func)
}
}