|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Update-scheme aware engine. More...
#include <tpl_ca_async_engine.H>
Public Types | |
| using | lattice_type = Lattice |
| using | rule_type = Rule |
| using | neighborhood_type = Neighborhood |
| using | scheme_type = Update_Scheme |
| using | state_type = typename Lattice::state_type |
| using | coord_type = typename Lattice::coord_type |
| using | extents_type = typename Lattice::extents_type |
| using | hook_type = std::function< void(std::size_t, const Lattice &)> |
Hook signature: (step_index, frame). | |
Public Member Functions | |
| Async_Engine (Lattice initial, Rule r, Neighborhood n, Update_Scheme s={}) | |
| Build an engine. | |
| Async_Engine (Lattice initial, Rule r, Update_Scheme s={}) | |
| Build an engine with a default-constructed neighborhood. | |
| const Lattice & | frame () const noexcept |
| std::size_t | steps_run () const noexcept |
| const extents_type & | extents () const noexcept |
| const Neighborhood & | neighborhood () const noexcept |
| Lattice & | current_buffer () noexcept |
| const Lattice & | current_buffer () const noexcept |
| Lattice & | write_lattice () noexcept |
Alias for current_buffer(). Used by checkpoint restore. | |
| void | set_step_count (const std::size_t s) noexcept |
| Override the completed-step counter. | |
| Lattice & | next_buffer () noexcept |
| Rule & | rule () noexcept |
| const Rule & | rule () const noexcept |
| const Update_Scheme & | scheme () const noexcept |
| std::size_t | step_count () const noexcept |
| void | swap_buffers () noexcept(noexcept(cur_.swap(nxt_))) |
| O(1) swap of the two buffers (called by double-buffer schemes). | |
| 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 () |
| Run one engine step using the configured update scheme. | |
| void | step_back () |
| Reverse the most recent step (Margolus only). | |
| void | run (const std::size_t steps) |
| Run several steps. | |
| void | run_back (const std::size_t steps) |
| Reverse several steps (Margolus only). | |
Static Public Attributes | |
| static constexpr std::size_t | rank = Lattice::rank |
| Lattice dimension. | |
Private Attributes | |
| Lattice | cur_ |
| Lattice | nxt_ |
| Rule | rule_ |
| Neighborhood | nh_ |
| Update_Scheme | scheme_ |
| hook_type | pre_hook_ |
| hook_type | post_hook_ |
| std::size_t | step_count_ = 0 |
Update-scheme aware engine.
Owns a current lattice buffer (and, when Update_Scheme::requires_double_buffer is true, a next buffer of identical extents). Each step() dispatches to the scheme's apply() method, which is responsible for visiting the cells in the desired order and updating the lattice in place or by double buffering.
| Lattice | lattice type. |
| Rule | rule (cell rule or block rule depending on the scheme). |
| Neighborhood | neighbourhood (Null_Neighborhood<Rank> for block-rule schemes). |
| Update_Scheme | update strategy (default Synchronous_Update<RowMajor>). |
Definition at line 162 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::coord_type = typename Lattice::coord_type |
Definition at line 177 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::extents_type = typename Lattice::extents_type |
Definition at line 178 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::hook_type = std::function<void(std::size_t, const Lattice &)> |
Hook signature: (step_index, frame).
Definition at line 184 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::lattice_type = Lattice |
Definition at line 171 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::neighborhood_type = Neighborhood |
Definition at line 173 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule_type = Rule |
Definition at line 172 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::scheme_type = Update_Scheme |
Definition at line 174 of file tpl_ca_async_engine.H.
| using Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::state_type = typename Lattice::state_type |
Definition at line 176 of file tpl_ca_async_engine.H.
|
inline |
Build an engine.
Allocates the next-buffer only when Update_Scheme::requires_double_buffer is true. For in-place schemes (Sequential, Random_Asynchronous, Margolus) the next-buffer member stays empty.
| [in] | initial | initial lattice (consumed by move). |
| [in] | r | rule instance (consumed by move). |
| [in] | n | neighborhood instance (consumed by move). |
| [in] | s | update-scheme instance (consumed by move). |
| std::bad_alloc | on allocation failure. |
Definition at line 209 of file tpl_ca_async_engine.H.
|
inline |
Build an engine with a default-constructed neighborhood.
| [in] | initial | initial lattice (consumed by move). |
| [in] | r | rule instance. |
| [in] | s | update-scheme instance. |
| std::bad_alloc | on allocation failure. |
Definition at line 222 of file tpl_ca_async_engine.H.
|
inlinenoexcept |
Definition at line 258 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_.
|
inlinenoexcept |
Definition at line 252 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_.
|
inlinenoexcept |
Definition at line 240 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_, and Aleph::CA::Lattice< Storage, Boundary >::extents().
|
inlinenoexcept |
Definition at line 228 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_.
|
inlinenoexcept |
Definition at line 246 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::nh_.
|
inlinenoexcept |
Definition at line 282 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::nxt_.
|
inline |
Register a hook fired after every step().
| F | callable accepting (std::size_t, const Lattice &). |
| [in] | f | hook to install. |
Definition at line 332 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::post_hook_.
|
inline |
Register a hook fired before every step().
| F | callable accepting (std::size_t, const Lattice &). |
| [in] | f | hook to install. |
Definition at line 322 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::pre_hook_.
|
inlinenoexcept |
Definition at line 294 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule_.
|
inlinenoexcept |
Definition at line 288 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule_.
|
inline |
Run several steps.
| [in] | steps | number of step() invocations. |
| Any | exception propagated by step(). |
Definition at line 396 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step(), and steps.
|
inline |
Reverse several steps (Margolus only).
| [in] | steps | number of step_back() invocations. |
| Any | exception propagated by step_back(). |
Definition at line 406 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back(), and steps.
|
inlinenoexcept |
Definition at line 300 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::scheme_.
|
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 275 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count_.
|
inline |
Run one engine step using the configured update scheme.
Calls refresh_halo() on lattices that have a halo, fires the pre-step hook, dispatches to scheme_.apply(*this, rule_), then fires the post-step hook.
| Any | exception propagated by the rule, the scheme or the hooks. |
Definition at line 346 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::post_hook_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::pre_hook_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::scheme_, and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count_.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::run(), and TEST().
|
inline |
Reverse the most recent step (Margolus only).
When the scheme exposes apply_with_origin(engine, rule, origin) (the Margolus contract) and the rule is an involution, applying the rule with the same partition origin that produced the forward step undoes the step bit-by-bit. This method decrements the step counter and re-applies the scheme with the parity that generated the now-discarded forward step.
steps_run() > 0. | std::out_of_range | if no step has been run yet. |
| Any | exception propagated by the rule or the scheme. |
Definition at line 374 of file tpl_ca_async_engine.H.
References ah_out_of_range_error_if, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::post_hook_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::pre_hook_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::scheme_, and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count_.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::run_back().
|
inlinenoexcept |
Definition at line 306 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count_.
|
inlinenoexcept |
step() calls. Definition at line 234 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count_.
|
inlinenoexcept |
O(1) swap of the two buffers (called by double-buffer schemes).
Definition at line 312 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::nxt_, and Aleph::CA::Lattice< Storage, Boundary >::swap().
|
inlinenoexcept |
Alias for current_buffer(). Used by checkpoint restore.
Definition at line 264 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_.
|
private |
Definition at line 187 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::current_buffer(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::current_buffer(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::extents(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::frame(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_buffers(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::write_lattice().
|
private |
Definition at line 190 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::neighborhood().
|
private |
Definition at line 188 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::next_buffer(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_buffers().
|
private |
Definition at line 193 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::on_post_step(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back().
|
private |
Definition at line 192 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::on_pre_step(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back().
|
staticconstexpr |
Lattice dimension.
Definition at line 181 of file tpl_ca_async_engine.H.
|
private |
Definition at line 189 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back().
|
private |
Definition at line 191 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::scheme(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back().
|
private |
Definition at line 194 of file tpl_ca_async_engine.H.
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::set_step_count(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::steps_run().