pnnl / lamellar-runtime

Lamellar is an asynchronous tasking runtime for HPC systems developed in RUST
Other
43 stars 5 forks source link

Expose lamellar running environment (like my_pe) in more general way #14

Closed JosephCottam closed 10 months ago

JosephCottam commented 1 year ago

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:

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 10 months ago

Implemented a LamellarEnv trait that exposes this functionality (https://github.com/pnnl/lamellar-runtime/commit/fcdfb1dc310fb61bf863b2708532a41ffca6dadb)

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);
    }
}