-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented LamellarEnv trait, available on world,team,arrays,darcs,m…
…emregions
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |