use lamellar::active_messaging::prelude::*;
#[lamellar::AmLocalData(Debug, Clone)]
struct ThreadIdAm;
#[lamellar::local_am]
impl LamellarAM for ThreadIdAm {
async fn exec(self) -> usize {
lamellar::tid
}
}
#[lamellar::main]
fn main() {
let world = lamellar::LamellarWorldBuilder::new().build();
let my_pe = world.my_pe();
let num_threads = world.num_threads_per_pe();
let team = world.team();
let world_clone = world.clone();
world_clone.block_on(async move {
let handles: Vec<_> = (0..num_threads)
.map(|thread| team.exec_am_local_thread(ThreadIdAm {}, thread).spawn())
.collect();
let thread_ids = world.join_all(handles).await;
let mut sorted = thread_ids.clone();
sorted.sort();
sorted.dedup();
println!(
"PE {my_pe}: all {num_threads} threads returned unique ids: {:?}",
thread_ids
);
});
world_clone.barrier();
}