Balancer

Struct Balancer 

Source
pub struct Balancer<O> {
    pub workers: usize,
    pub rank: usize,
    pub size: usize,
    /* private fields */
}
Expand description

This struct helps manage compute on a given node and across nodes

Fields§

§workers: usize§rank: usize§size: usize

Implementations§

Source§

impl<O> Balancer<O>
where O: Send + Equivalence,

Source

pub fn new(universe: Arc<Universe>, verbose: bool) -> Self

Constructs a new Balancer from an mpi::SystemCommunicator a.k.a. world.

Examples found in repository?
examples/simple.rs (line 24)
15fn experiment(universe: Arc<Universe>) {
16    // Get relevant portion of data on this node
17    let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
18
19    // Define task
20    let work = |x: &f64| x * x;
21
22    // Initialize balancer, work and collect
23    let verbose = false;
24    let balancer = Balancer::new(universe, verbose);
25    balancer.work_subset(&data, work);
26    let output = balancer.collect();
27
28    // That's it!
29    // Let's do some verification
30    if balancer.rank == 0 {
31        for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
32            assert_eq!(expected, *actual);
33        }
34    }
35}
More examples
Hide additional examples
examples/distribute.rs (line 30)
21fn experiment(universe: Arc<Universe>) {
22    // Get relevant portion of data on this node
23    let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
24
25    // Define task
26    let work = |x: &f64| x * x;
27
28    // Initialize balancer, work and collect
29    let verbose = false;
30    let balancer = Balancer::new(universe, verbose);
31    let ours = balancer.distribute(Some(data.clone())).unwrap();
32    balancer.work(&ours, work);
33    let output = balancer.collect();
34
35    // That's it!
36    // Let's do some verification
37    if balancer.rank == 0 {
38        for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
39            assert_eq!(expected, *actual);
40        }
41    }
42}
43
44fn helper(universe: Arc<Universe>) {
45    // Initialize balancer
46    let verbose = false;
47    let balancer = Balancer::new(universe, verbose);
48
49    // Get relevant portion of data on this node
50    // rank !=0 passes in none
51    let data: Vec<f64> = balancer.distribute(None).unwrap();
52
53    // Define task
54    let work = |x: &f64| x * x;
55
56    balancer.work(&data, work);
57    balancer.collect();
58}
Source

pub fn work_subset<'b, I, F>(&self, items: &'b [I], work: F)
where I: Send + Sync, F: Fn(&'b I) -> O + Send + Sync, O: Send,

Calculates local set of items on which to work on.

Examples found in repository?
examples/simple.rs (line 25)
15fn experiment(universe: Arc<Universe>) {
16    // Get relevant portion of data on this node
17    let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
18
19    // Define task
20    let work = |x: &f64| x * x;
21
22    // Initialize balancer, work and collect
23    let verbose = false;
24    let balancer = Balancer::new(universe, verbose);
25    balancer.work_subset(&data, work);
26    let output = balancer.collect();
27
28    // That's it!
29    // Let's do some verification
30    if balancer.rank == 0 {
31        for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
32            assert_eq!(expected, *actual);
33        }
34    }
35}
Source

pub fn work<'b, I, F>(&self, items: &'b [I], work: F)
where I: Send + Sync, F: Fn(&'b I) -> O + Send + Sync, O: Send,

Works on the entire set provided

Examples found in repository?
examples/distribute.rs (line 32)
21fn experiment(universe: Arc<Universe>) {
22    // Get relevant portion of data on this node
23    let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
24
25    // Define task
26    let work = |x: &f64| x * x;
27
28    // Initialize balancer, work and collect
29    let verbose = false;
30    let balancer = Balancer::new(universe, verbose);
31    let ours = balancer.distribute(Some(data.clone())).unwrap();
32    balancer.work(&ours, work);
33    let output = balancer.collect();
34
35    // That's it!
36    // Let's do some verification
37    if balancer.rank == 0 {
38        for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
39            assert_eq!(expected, *actual);
40        }
41    }
42}
43
44fn helper(universe: Arc<Universe>) {
45    // Initialize balancer
46    let verbose = false;
47    let balancer = Balancer::new(universe, verbose);
48
49    // Get relevant portion of data on this node
50    // rank !=0 passes in none
51    let data: Vec<f64> = balancer.distribute(None).unwrap();
52
53    // Define task
54    let work = |x: &f64| x * x;
55
56    balancer.work(&data, work);
57    balancer.collect();
58}
Source

pub fn distribute<'b, I>(&self, items: Option<Vec<I>>) -> Option<Vec<I>>
where I: Send + Sync + Equivalence,

Distributes items for work

Examples found in repository?
examples/distribute.rs (line 31)
21fn experiment(universe: Arc<Universe>) {
22    // Get relevant portion of data on this node
23    let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
24
25    // Define task
26    let work = |x: &f64| x * x;
27
28    // Initialize balancer, work and collect
29    let verbose = false;
30    let balancer = Balancer::new(universe, verbose);
31    let ours = balancer.distribute(Some(data.clone())).unwrap();
32    balancer.work(&ours, work);
33    let output = balancer.collect();
34
35    // That's it!
36    // Let's do some verification
37    if balancer.rank == 0 {
38        for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
39            assert_eq!(expected, *actual);
40        }
41    }
42}
43
44fn helper(universe: Arc<Universe>) {
45    // Initialize balancer
46    let verbose = false;
47    let balancer = Balancer::new(universe, verbose);
48
49    // Get relevant portion of data on this node
50    // rank !=0 passes in none
51    let data: Vec<f64> = balancer.distribute(None).unwrap();
52
53    // Define task
54    let work = |x: &f64| x * x;
55
56    balancer.work(&data, work);
57    balancer.collect();
58}
Source

pub fn collect(&self) -> Option<Vec<O>>

Examples found in repository?
examples/simple.rs (line 26)
15fn experiment(universe: Arc<Universe>) {
16    // Get relevant portion of data on this node
17    let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
18
19    // Define task
20    let work = |x: &f64| x * x;
21
22    // Initialize balancer, work and collect
23    let verbose = false;
24    let balancer = Balancer::new(universe, verbose);
25    balancer.work_subset(&data, work);
26    let output = balancer.collect();
27
28    // That's it!
29    // Let's do some verification
30    if balancer.rank == 0 {
31        for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
32            assert_eq!(expected, *actual);
33        }
34    }
35}
More examples
Hide additional examples
examples/distribute.rs (line 33)
21fn experiment(universe: Arc<Universe>) {
22    // Get relevant portion of data on this node
23    let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
24
25    // Define task
26    let work = |x: &f64| x * x;
27
28    // Initialize balancer, work and collect
29    let verbose = false;
30    let balancer = Balancer::new(universe, verbose);
31    let ours = balancer.distribute(Some(data.clone())).unwrap();
32    balancer.work(&ours, work);
33    let output = balancer.collect();
34
35    // That's it!
36    // Let's do some verification
37    if balancer.rank == 0 {
38        for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
39            assert_eq!(expected, *actual);
40        }
41    }
42}
43
44fn helper(universe: Arc<Universe>) {
45    // Initialize balancer
46    let verbose = false;
47    let balancer = Balancer::new(universe, verbose);
48
49    // Get relevant portion of data on this node
50    // rank !=0 passes in none
51    let data: Vec<f64> = balancer.distribute(None).unwrap();
52
53    // Define task
54    let work = |x: &f64| x * x;
55
56    balancer.work(&data, work);
57    balancer.collect();
58}
Source

pub fn barrier(&mut self)

Waits for all threads to finish across all ranks.

Auto Trait Implementations§

§

impl<O> !Freeze for Balancer<O>

§

impl<O> !RefUnwindSafe for Balancer<O>

§

impl<O> !Send for Balancer<O>

§

impl<O> !Sync for Balancer<O>

§

impl<O> Unpin for Balancer<O>
where O: Unpin,

§

impl<O> UnwindSafe for Balancer<O>
where O: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
Source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

Source§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
Source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, Dst> ConvAsUtil<Dst> for T

Source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
Source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
Source§

impl<T> ConvUtil for T

Source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
Source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
Source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
Source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
Source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<Src> TryFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

Source§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<Src> ValueFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
Source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

Source§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.