pnnl / lamellar-runtime

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

memregion::dist trait private #2

Closed rdfriese closed 2 years ago

rdfriese commented 2 years ago

Cannot bound generic by memregion::Dist from user code

github-actions[bot] commented 2 years ago

Branch issue-2-memregion_dist_trait_private created!

rdfriese commented 2 years ago

@JosephCottam Is this similar to your use case?

use lamellar::array::{UnsafeArray,Distribution};
use lamellar::{LamellarWorld,Dist};

struct ArrayWrapper<T>{
    array: UnsafeArray<T>
}

impl<T: Dist + Clone> ArrayWrapper<T>{
    fn new(world: &LamellarWorld, len: usize) -> Self{
        ArrayWrapper{
            array: UnsafeArray::<T>::new(world,len,Distribution::Block)
        }
    }
}

fn main() {
    let world = lamellar::LamellarWorldBuilder::new().build();
    let my_pe = world.my_pe();
    let _num_pes = world.num_pes();
    let wrapped_array_f32 = ArrayWrapper::<f32>::new(&world,10);
    let wrapped_array_usize = ArrayWrapper::<f32>::new(&world,10);
}
JosephCottam commented 2 years ago

That is basically what I wanted to do, but it won't quite work as written there.

I pushed public_memregion branch with an example and a fix that makes it work.

Beyond what you have there, you also have to have implement serde::de::DeserializeOwned and serde::ser::Serialize. It would be nice if Dist somehow capture that idea (or if it was something more common like Clone or Copy instead of that pair).

JosephCottam commented 2 years ago

@rdfriese I have confirmed that branch issue-2-memregion_dist_trait_private solves the problem in my code. (And I think its cleaner than the public_memregion branch solution...so use yours not mine!)