Attribute Macro lamellar::active_messaging::am

source ·
#[am]
Expand description

This macro is used to associate an implemenation of LamellarAM for type that has used the AmData attribute macro

This essentially constructs and registers the Active Message with the runtime. It is responsible for ensuring all data within the active message is properly serialize and deserialized, including any returned results.

Each active message implementation is assigned a unique ID at runtime initialization, these IDs are then used as the key to a Map containing specialized deserialization functions that convert a slice of bytes into the appropriate data type on the remote PE. Finally, a worker thread will call that deserialized objects exec() function to execute the actual active message.

Please see the Active Messaging module level documentation for more details

§Examples

 use lamellar::active_messaging::prelude::*;
 use lamellar::darc::prelude::*;

 #[AmData(Debug,Clone)]
 struct HelloWorld {
    originial_pe: usize,
    #[AmData(static)]
    msg: Darc<String>,
 }

 #[lamellar::am]
 impl LamellarAM for HelloWorld {
     async fn exec(self) {
         println!(
             "{:?}}  on PE {:?} of {:?} using thread {:?}, received from PE {:?}",
             self.msg,
             lamellar::current_pe,
             lamellar::num_pes,
             std::thread::current().id(),
             self.originial_pe.lock(),
         );
     }
 }
 fn main() {
     let world = lamellar::LamellarWorldBuilder::new().build();
     let my_pe = world.my_pe();
     world.barrier();
     let msg = Darc::<String>::new(&world, "Hello World".to_string());
     //Send a Hello World Active Message to all pes
     let request = world.exec_am_all(HelloWorld {
         originial_pe: my_pe,
         msg: msg,
     });

     //wait for the request to complete
     world.block_on(request);
 } //when world drops there is an implicit world.barrier() that occurs