extern crate timely_communication;
use std::ops::Deref;
use timely_communication::{Message, Allocate};
fn main() {
let config = timely_communication::Config::from_args(std::env::args()).unwrap();
let guards = timely_communication::initialize(config, |mut allocator| {
println!("worker {} of {} started", allocator.index(), allocator.peers());
let (mut senders, mut receiver) = allocator.allocate(0);
for i in 0 .. allocator.peers() {
senders[i].send(Message::from_typed(format!("hello, {}", i)));
senders[i].done();
}
let mut received = 0;
while received < allocator.peers() {
allocator.receive();
if let Some(message) = receiver.recv() {
println!("worker {}: received: <{}>", allocator.index(), message.deref());
received += 1;
}
allocator.release();
}
allocator.index()
});
if let Ok(guards) = guards {
for guard in guards.join() {
println!("result: {:?}", guard);
}
}
else { println!("error in computation"); }
}