Macro build_communicator
build_communicator!() { /* proc-macro */ }
Available on crate feature
chili
only.Expand description
Automatically build communicator struct depending on simulation aspects.
This macro internally constructs a new struct with fields for every given simulation aspect. Each field is a ChannelComm struct with different types.
It also automatically derives the FromMap trait such that a collection of communicators can be constructed from a given map.
use cellular_raza_core::backend::chili::build_communicator;
build_communicator!(
// Which simulation aspects and informatino exchange should be satisfied.
aspects: [Cycle],
// Path to the core library. Use `cellular_raza::core` when
// import from the `cellular_raza` crate.
core_path: cellular_raza_core,
// Define the name of the generated struct
communicator_name: MyCommunicator,
);
// Use the new struct in the following.
use cellular_raza_core::backend::chili::FromMap;
let new_map = std::collections::BTreeMap::from([
(0, std::collections::BTreeSet::from([1,3])),
(1, std::collections::BTreeSet::from([0,2])),
(2, std::collections::BTreeSet::from([1,3])),
(3, std::collections::BTreeSet::from([2,0])),
]);
let communicators = MyCommunicator::from_map(&new_map).unwrap();
assert_eq!(communicators.len(), 4);