Crates.io | balancer |
lib.rs | balancer |
version | 0.2.0 |
source | src |
created_at | 2019-05-26 00:54:11.325073 |
updated_at | 2023-03-05 23:36:49.931857 |
description | Use rayon and mpi to achieve simple forms of internode + intranode parallelism. |
homepage | |
repository | https://github.com/cavemanloverboy/balancer |
max_upload_size | |
id | 137042 |
size | 35,536 |
With the power of rayon
and mpi
, internode and intranode parallelism is achieved for simple tasks.
See examples/simple.rs
.
use std::sync::Arc;
use balancer::Balancer;
use mpi::environment::Universe;
fn main() {
let universe = Arc::new(mpi::initialize().unwrap());
experiment(universe.clone());
experiment(universe.clone());
}
fn experiment(universe: Arc<Universe>) {
// Get relevant portion of data on this node
let data: Vec<f64> = (0..100_000).map(|x| x as f64 / 100_000.0).collect();
// Define task
let work = |x: &f64| x * x;
// Initialize balancer, work and collect
let verbose = false;
let balancer = Balancer::new(universe, verbose);
balancer.work_local(&data, work);
let output = balancer.collect();
// That's it!
// Let's do some verification
if balancer.rank == 0 {
for (expected, actual) in data.iter().map(work).zip(output.as_ref().unwrap()) {
assert_eq!(expected, *actual);
}
}
}