Expose lamellar running environment (like my_pe) in more general way
JosephCottam opened this issue · 1 comments
JosephCottam commented
my_pe
and num_pes
are not consistently accessible. Making them consistently accessible enables instrumentation (like a generic lamellar_trace
that will print the current PE if known).
Options include:
- Making
my_pe
andnum_pes
part of anlamellar_environment
trait (or something similar...names are hard) that Lamellar arrays types, teams and world all implement. - A crate-functions like
lamellar_env::my_pe()
that can introspect the current running environment.
Candidates for this type of accessibility include the current world identifier, the current team identifier, the current pe identifier and the number of worlds/teams/pes.
rdfriese commented
Implemented a LamellarEnv trait that exposes this functionality (fcdfb1d)
below is an example how to use it (and can be found at: https://github.com/pnnl/lamellar-runtime/blob/dev/examples/misc/lamellar_env.rs
/// This example simply showcases the LamellarEnv Trait
use lamellar::array::prelude::*;
use lamellar::darc::prelude::*;
use lamellar::lamellar_env::LamellarEnv;
fn print_env<T: LamellarEnv>(env: &T) {
println!("my_pe: {}", env.my_pe());
println!("num_pes: {}", env.num_pes());
println!("num_threads_per_pe: {}", env.num_threads_per_pe());
println!("world: {:?}", env.world());
println!("team: {:?}", env.team());
println!();
}
fn main() {
let world = LamellarWorldBuilder::new().build();
let darc = Darc::new(&world, 0).unwrap();
let lrw_darc = LocalRwDarc::new(&world, 0).unwrap();
let grw_darc = GlobalRwDarc::new(&world, 0).unwrap();
let array = UnsafeArray::<u8>::new(world.clone(), 10, Distribution::Block);
let team = world
.create_team_from_arch(StridedArch::new(0, 2, world.num_pes() / 2))
.unwrap();
println!("environment from world");
print_env(&world);
println!("environment from darc");
print_env(&darc);
println!("environment from lrw_darc");
print_env(&lrw_darc);
println!("environment from grw_darc");
print_env(&grw_darc);
println!("environment from UnsafeArray");
print_env(&array);
let array = array.into_atomic();
println!("environment from AtomicArray");
print_env(&array);
let array = array.into_local_lock();
println!("environment from LocalOnlyArray");
print_env(&array);
let array = array.into_global_lock();
println!("environment from GlobalLockArray");
print_env(&array);
if world.my_pe() % 2 == 0 {
println!("environment from team");
print_env(&team);
}
}