Skip to content

Commit

Permalink
Implemented LamellarEnv trait, available on world,team,arrays,darcs,m…
Browse files Browse the repository at this point in the history
…emregions
  • Loading branch information
rdfriese committed Oct 27, 2023
1 parent e21605b commit fcdfb1d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
48 changes: 48 additions & 0 deletions examples/misc/lamellar_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/// This example simply showcases the LamellarEnv Trait
use lamellar::array::prelude::*;
use lamellar::darc::prelude::*;
use lamellar::lamellar_env::LamellarEnv;
use lamellar::memregion::prelude::*;

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);
}
}
26 changes: 26 additions & 0 deletions src/lamellar_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::AtomicArray;
use crate::Dist;
use crate::LamellarTeam;
use enum_dispatch::enum_dispatch;
use std::sync::Arc;

/// A trait for accessing various data about the current lamellar envrionment
#[enum_dispatch]
pub trait LamellarEnv {
/// Return the PE id of the calling PE,
/// if called on a team instance, the PE id will be with respect to the team
/// (not to the world)
fn my_pe(&self) -> usize;

/// Return the number of PEs in the execution
fn num_pes(&self) -> usize;

/// Return the number of threads per PE
fn num_threads_per_pe(&self) -> usize;

/// Return a pointer the world team
fn world(&self) -> Arc<LamellarTeam>;

/// Return a pointer to the LamellarTeam
fn team(&self) -> Arc<LamellarTeam>;
}

0 comments on commit fcdfb1d

Please sign in to comment.