use lamellar::ActiveMessaging;
#[lamellar::AmData(Clone, Debug)]
struct RecursiveAM {
next: usize,
orig: usize,
}
#[lamellar::am]
impl LamellarAM for RecursiveAM {
async fn exec(&self) -> Vec<String> {
println!(
"\tin RecursiveAM {:?} on pe {:?} of {:?} ({:?})",
self,
lamellar::current_pe,
lamellar::num_pes,
hostname::get().unwrap().into_string().unwrap()
);
let next_pe = (self.next + 1) % lamellar::team.num_pes() as usize;
if next_pe == self.orig {
let mut res = Vec::new();
res.push(hostname::get().unwrap().into_string().unwrap()); res
} else {
std::thread::sleep(std::time::Duration::from_millis(1000 as u64));
let next = lamellar::world.exec_am_pe(
next_pe,
RecursiveAM {
next: next_pe,
orig: self.orig,
},
);
let mut res = next.await;
res.push(hostname::get().unwrap().into_string().unwrap()); res
}
}
}
#[lamellar::main]
fn main() {
let world = lamellar::LamellarWorldBuilder::new().build();
let my_pe = world.my_pe();
world.barrier();
if my_pe == 0 {
println!("---------------------------------------------------------------");
println!("testing recursive am");
let res = world
.exec_am_pe(
my_pe,
RecursiveAM {
next: my_pe,
orig: my_pe,
},
)
.block();
println!("visit paths: {:?}", res);
println!("---------------------------------------------------------------");
}
world.barrier();
}