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: usizeImplementations§
Source§impl<O> Balancer<O>where
O: Send + Equivalence,
impl<O> Balancer<O>where
O: Send + Equivalence,
Sourcepub fn new(universe: Arc<Universe>, verbose: bool) -> Self
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
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}Sourcepub fn work_subset<'b, I, F>(&self, items: &'b [I], work: F)
pub fn work_subset<'b, I, F>(&self, items: &'b [I], work: F)
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}Sourcepub fn work<'b, I, F>(&self, items: &'b [I], work: F)
pub fn work<'b, I, F>(&self, items: &'b [I], work: F)
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}Sourcepub fn distribute<'b, I>(&self, items: Option<Vec<I>>) -> Option<Vec<I>>
pub fn distribute<'b, I>(&self, items: Option<Vec<I>>) -> Option<Vec<I>>
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}Sourcepub fn collect(&self) -> Option<Vec<O>>
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
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}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<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
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 Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
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>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
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>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Approximate the subject to a given type with a specific scheme.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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