Trait Communicator

pub trait Communicator<I, T>: Sized {
    // Required methods
    fn send(&mut self, receiver: &I, message: T) -> Result<(), SimulationError>;
    fn receive(&mut self) -> Vec<T>;
}
Available on crate feature chili only.
Expand description

Handles communications between different simulation processes.

Often times, information needs to be exchanged between threads. For example, positional and force information of cells living at the boundary.

The receiver is referenced by the index I and will obtain the message T. The trait was designed around the [crossbeam_channel] sender-receiver pair. However, it should allow for more generic setups where eg. information could be shared by different means such as sharing memory.

Between the Communicator::send and Communicator::receive method, a synchronization step needs to happen. Otherwise, dataraces can occur and invalidate given results. See the Sync trait for more details on syncing between threads.

Required Methods§

fn send(&mut self, receiver: &I, message: T) -> Result<(), SimulationError>

Sends information to a particular receiver.

fn receive(&mut self) -> Vec<T>

Receives the information previously sent

When implementing this trait, make sure to empty any existing queue or shared memory. Otherwise received messages will be stacking up, using up more memory+ and yielding wrong results.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<I, T> Communicator<I, T> for ChannelComm<I, T>
where I: Hash + Eq + Ord,