|
Aleph-w 7.10.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. | |
| Async_Engine (const Async_Engine &other)=default | |
| Copy another engine: its lattices, its rule, its neighborhood, its update scheme, its hooks and its count of steps. | |
| Async_Engine (Async_Engine &&other) noexcept(std::is_nothrow_move_constructible_v< Lattice > and std::is_nothrow_move_constructible_v< Rule > and std::is_nothrow_move_constructible_v< Neighborhood > and std::is_nothrow_move_constructible_v< Update_Scheme >) | |
| Take the simulation of another engine, which is left with empty lattices, no hooks and no steps run. | |
| Async_Engine & | operator= (const Async_Engine &other)=default |
| Copy another engine into this one: its lattices, its rule, its neighborhood, its update scheme, its hooks and its count of steps. | |
| Async_Engine & | operator= (Async_Engine &&other) noexcept(noexcept(swap(other))) |
| Exchange this engine with another, which is left with the previous simulation of this one. | |
| void | swap (Async_Engine &other) noexcept(noexcept(cur_.swap(other.cur_)) and std::is_nothrow_swappable_v< Rule > and std::is_nothrow_swappable_v< Neighborhood > and std::is_nothrow_swappable_v< Update_Scheme >) |
| Exchange in O(1) the simulation of this engine and another. | |
| 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 Member Functions | |
| void | swap_all_or_none (Async_Engine &other) |
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.
|
default |
Copy another engine: its lattices, its rule, its neighborhood, its update scheme, its hooks and its count of steps.
| [in] | other | engine to copy. |
|
inlinenoexcept |
Take the simulation of another engine, which is left with empty lattices, no hooks and no steps run.
The implicit move took the lattices but copied the step counter: the moved-from engine reported the steps of a simulation that it no longer had.
| [in,out] | other | engine to move from. |
Definition at line 242 of file tpl_ca_async_engine.H.
|
inlinenoexcept |
Definition at line 387 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_.
|
inlinenoexcept |
Definition at line 381 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_.
|
inlinenoexcept |
Definition at line 369 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 357 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::cur_.
Referenced by TEST().
|
inlinenoexcept |
Definition at line 375 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::nh_.
|
inlinenoexcept |
Definition at line 411 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 461 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 451 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::pre_hook_.
|
inlinenoexcept |
Exchange this engine with another, which is left with the previous simulation of this one.
| [in,out] | other | engine to move from. |
Definition at line 266 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap().
|
default |
Copy another engine into this one: its lattices, its rule, its neighborhood, its update scheme, its hooks and its count of steps.
| [in] | other | engine to copy. |
|
inlinenoexcept |
Definition at line 423 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule_.
|
inlinenoexcept |
Definition at line 417 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 525 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 535 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 429 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 404 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 475 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().
|
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 503 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 435 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 363 of file tpl_ca_async_engine.H.
References Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count_.
|
inlinenoexcept |
Exchange in O(1) the simulation of this engine and another.
| [in,out] | other | engine to exchange with. |
| what | swapping the rules, the neighborhoods, the update schemes or the lattices throws. When one of those swaps may throw, the rules, the neighborhoods and the schemes are exchanged before the lattices, all or none: if a swap throws, those before it are exchanged back, and both engines are left as they were, if the swap that threw left its arguments as they were. If a swap that puts one back throws too, both engines can only be destroyed or assigned. std::swap(), for a rule without a swap of its own, may leave it moved from. |
Definition at line 286 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 >::nh_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::nxt_, 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_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_count_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap(), Aleph::CA::Lattice< Storage, Boundary >::swap(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_all_or_none().
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::operator=(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_all_or_none().
|
inlineprivate |
Definition at line 324 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 >::nh_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::nxt_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::rule_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::scheme_, Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap(), and Aleph::CA::Lattice< Storage, Boundary >::swap().
Referenced by Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap().
|
inlinenoexcept |
O(1) swap of the two buffers (called by double-buffer schemes).
Definition at line 441 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 393 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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_all_or_none(), 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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_all_or_none().
|
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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_all_or_none(), 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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap().
|
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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap().
|
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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_all_or_none().
|
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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::step_back(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap_all_or_none().
|
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(), Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::steps_run(), and Aleph::CA::Async_Engine< Lattice, Rule, Neighborhood, Update_Scheme >::swap().