|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Synchronous double-buffered engine. More...
#include <tpl_ca_engine.H>
Public Types | |
| using | lattice_type = Lattice |
| Lattice type. | |
| using | rule_type = Rule |
| Rule type. | |
| using | neighborhood_type = Neighborhood |
| Neighborhood type. | |
| using | order_type = Order |
| Iteration order. | |
| using | state_type = typename Lattice::state_type |
| Cell state type. | |
| using | coord_type = typename Lattice::coord_type |
| Coordinate type. | |
| using | extents_type = typename Lattice::extents_type |
| Extents type. | |
| using | hook_type = std::function< void(std::size_t, const Lattice &)> |
Hook signature: (step_index_just_completed, frame). | |
Public Member Functions | |
| Synchronous_Engine (Lattice initial, Rule r, Neighborhood n) | |
| Build an engine on top of an existing initial lattice. | |
| Synchronous_Engine (Lattice initial, Rule r) | |
| Build an engine with a default-constructed neighbourhood. | |
| const Lattice & | frame () const noexcept |
| Return the current frame. | |
| std::size_t | steps_run () const noexcept |
| Return the number of completed steps. | |
| const extents_type & | extents () const noexcept |
| Return the frame extents. | |
| const Rule & | rule () const noexcept |
| Read-only access to the rule (used by checkpointing). | |
| Rule & | rule () noexcept |
| Mutable access to the rule (used by checkpointing to restore the master RNG seed of stochastic rules). | |
| Lattice & | write_lattice () noexcept |
| Mutable access to the current lattice buffer. | |
| void | set_step_count (const std::size_t s) noexcept |
| Override the completed-step counter. | |
| template<typename F > | |
| void | on_pre_step (F &&f) |
Register a hook fired before every step(). | |
| template<typename F > | |
| void | on_post_step (F &&f) |
Register a hook fired after every step(). | |
| void | step () |
| Apply the rule to every cell once and swap buffers. | |
| void | run (const std::size_t steps) |
| Run several synchronous steps. | |
Static Public Attributes | |
| static constexpr std::size_t | rank = Lattice::rank |
| Lattice dimension. | |
| static constexpr std::size_t | neighbour_count = Neighborhood::size_v |
| Number of neighbours. | |
Private Attributes | |
| Lattice | cur_buf_ |
| Lattice | nxt_buf_ |
| Rule | rule_ |
| Neighborhood | nh_ |
| hook_type | pre_hook_ |
| hook_type | post_hook_ |
| std::size_t | step_count_ = 0 |
Synchronous double-buffered engine.
| Lattice | lattice type (e.g. Lattice<Dense_Cell_Storage<int,2>, ToroidalBoundary>). |
| Rule | rule type satisfying RuleLike<Rule, Lattice>. |
| Neighborhood | neighbourhood type satisfying NeighborhoodLike. |
| Order | iteration order tag (RowMajor or Tile<W, H>). |
step() is O(N * S) where N is the cell count and S the neighbour count. Buffer swap is O(1).Definition at line 183 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::coord_type = typename Lattice::coord_type |
Coordinate type.
Definition at line 204 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::extents_type = typename Lattice::extents_type |
Extents type.
Definition at line 206 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::hook_type = std::function<void(std::size_t, const Lattice &)> |
Hook signature: (step_index_just_completed, frame).
Definition at line 214 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::lattice_type = Lattice |
Lattice type.
Definition at line 193 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::neighborhood_type = Neighborhood |
Neighborhood type.
Definition at line 197 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::order_type = Order |
Iteration order.
Definition at line 199 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::rule_type = Rule |
Rule type.
Definition at line 195 of file tpl_ca_engine.H.
| using Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::state_type = typename Lattice::state_type |
Cell state type.
Definition at line 202 of file tpl_ca_engine.H.
|
inline |
Build an engine on top of an existing initial lattice.
The next-step buffer is allocated with the same extents and a default-constructed cell value.
| [in] | initial | initial lattice (consumed by move). |
| [in] | r | rule instance. |
| [in] | n | neighbourhood instance. |
| std::bad_alloc | if allocating the next buffer fails. |
Definition at line 240 of file tpl_ca_engine.H.
|
inline |
Build an engine with a default-constructed neighbourhood.
This overload is available only when Neighborhood is default constructible.
| [in] | initial | initial lattice (consumed by move). |
| [in] | r | rule instance. |
| std::bad_alloc | if allocating the next buffer fails. |
Definition at line 257 of file tpl_ca_engine.H.
|
inlinenoexcept |
Return the frame extents.
Definition at line 284 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::cur_buf_, and Aleph::CA::Lattice< Storage, Boundary >::extents().
|
inlinenoexcept |
Return the current frame.
Definition at line 266 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::cur_buf_.
Referenced by expect_engine_equivalence(), main(), TEST(), and TEST().
|
inline |
Register a hook fired after every step().
The hook receives the step index that just completed (steps_run() after the swap) and a const reference to the resulting frame.
Definition at line 347 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::post_hook_.
|
inline |
Register a hook fired before every step().
The hook receives the step index that is about to start (steps_run()) and a const reference to the current frame.
Definition at line 336 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::pre_hook_.
|
inlinenoexcept |
Read-only access to the rule (used by checkpointing).
Definition at line 292 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::rule_.
|
inlinenoexcept |
Mutable access to the rule (used by checkpointing to restore the master RNG seed of stochastic rules).
Definition at line 301 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::rule_.
|
inline |
Run several synchronous steps.
| [in] | steps | number of consecutive step() calls to perform. |
| Any | exception propagated by step(). |
Definition at line 432 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step(), and steps.
Referenced by expect_engine_equivalence(), main(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Override the completed-step counter.
Used by load_checkpoint_into to resume a simulation from the exact step recorded in the snapshot.
| [in] | s | new step counter value. |
Definition at line 326 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step_count_.
|
inline |
Apply the rule to every cell once and swap buffers.
step() gathers neighbours into a fixed-size stack buffer, writes the result into the next buffer, swaps the buffers in O(1), then fires the optional post-step hook.
| Any | exception propagated by the rule, lattice or hooks. |
Definition at line 363 of file tpl_ca_engine.H.
References Aleph::CA::apply_rule(), Aleph::CA::Lattice< Storage, Boundary >::at(), Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::cur_buf_, Aleph::CA::gather_neighbors(), Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::nh_, Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::nxt_buf_, Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::post_hook_, Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::pre_hook_, Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::rank, Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::rule_, Aleph::CA::Lattice< Storage, Boundary >::set(), Aleph::CA::Lattice< Storage, Boundary >::size(), Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step_count_, and Aleph::CA::Lattice< Storage, Boundary >::swap().
Referenced by main(), Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::run(), run_engine_equivalence(), TEST(), and TEST().
|
inlinenoexcept |
Return the number of completed steps.
step() invocations performed so far. Definition at line 275 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step_count_.
Referenced by expect_engine_equivalence().
|
inlinenoexcept |
Mutable access to the current lattice buffer.
Provided to support checkpoint restore (load_checkpoint_into): the loader rewrites every cell in place. Mutating the lattice outside of step() is otherwise discouraged.
Definition at line 314 of file tpl_ca_engine.H.
References Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::cur_buf_.
|
private |
Definition at line 217 of file tpl_ca_engine.H.
Referenced by Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::extents(), Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::frame(), Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step(), and Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::write_lattice().
|
staticconstexpr |
Number of neighbours.
Definition at line 211 of file tpl_ca_engine.H.
|
private |
Definition at line 220 of file tpl_ca_engine.H.
Referenced by Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step().
|
private |
Definition at line 218 of file tpl_ca_engine.H.
Referenced by Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step().
|
private |
Definition at line 222 of file tpl_ca_engine.H.
Referenced by Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::on_post_step(), and Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step().
|
private |
Definition at line 221 of file tpl_ca_engine.H.
Referenced by Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::on_pre_step(), and Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step().
|
staticconstexpr |
Lattice dimension.
Definition at line 209 of file tpl_ca_engine.H.
Referenced by Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step().
|
private |
|
private |
Definition at line 223 of file tpl_ca_engine.H.
Referenced by Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::set_step_count(), Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::step(), and Aleph::CA::Synchronous_Engine< Lattice, Rule, Neighborhood, Order >::steps_run().