69#ifndef TPL_CA_ASYNC_ENGINE_H
70#define TPL_CA_ASYNC_ENGINE_H
87namespace ca_async_engine_detail {
93template <
typename Scheme,
typename Engine,
typename Rule>
95 =
requires(
const Scheme &s, Engine &e, Rule &
r,
ca_index_t o) { s.apply_with_origin(e,
r, o); };
109template <std::
size_t Rank>
114 static constexpr std::size_t
rank_v = Rank;
125 [[nodiscard]]
static constexpr std::size_t
radius() noexcept
133 [[nodiscard]]
static constexpr std::size_t
size() noexcept
141 template <
typename F>
161template <
typename Lattice,
typename Rule,
typename Neighborhood,
typename Update_Scheme = Synchronous_Update<RowMajor>>
166 "Async_Engine requires a NeighborhoodLike neighborhood (use Null_Neighborhood for "
168 static_assert(Neighborhood::rank_v ==
Lattice::rank,
"Neighborhood rank must match lattice rank");
212 if constexpr (Update_Scheme::requires_double_buffer)
223 requires std::default_initializable<Neighborhood>
243 std::is_nothrow_move_constructible_v<Lattice>
and std::is_nothrow_move_constructible_v<Rule>
244 and std::is_nothrow_move_constructible_v<Neighborhood>
245 and std::is_nothrow_move_constructible_v<Update_Scheme>)
267 requires (std::swappable<Rule>
and std::swappable<Neighborhood>
268 and std::swappable<Update_Scheme>)
287 noexcept(
cur_.
swap(other.cur_))
and std::is_nothrow_swappable_v<Rule>
288 and std::is_nothrow_swappable_v<Neighborhood>
and std::is_nothrow_swappable_v<Update_Scheme>)
289 requires (std::swappable<Rule>
and std::swappable<Neighborhood>
290 and std::swappable<Update_Scheme>)
300 constexpr bool may_throw =
301 not std::is_nothrow_swappable_v<Rule> or not std::is_nothrow_swappable_v<Neighborhood>
302 or not std::is_nothrow_swappable_v<Update_Scheme> or not
noexcept(
cur_.
swap(other.cur_));
304 if constexpr (may_throw)
417 [[nodiscard]] Rule &
rule() noexcept
423 [[nodiscard]]
const Rule &
rule() const noexcept
429 [[nodiscard]]
const Update_Scheme &
scheme() const noexcept
450 template <
typename F>
460 template <
typename F>
504 requires ca_async_engine_detail::HasApplyWithOrigin<Update_Scheme,
Async_Engine, Rule>
527 for (std::size_t i = 0; i <
steps; ++i)
538 for (std::size_t i = 0; i <
steps; ++i)
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Common typedefs and tag types for the Cellular Automata module.
Update-scheme aware engine.
const Lattice & frame() const noexcept
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.
Lattice & current_buffer() noexcept
void step_back()
Reverse the most recent step (Margolus only).
std::size_t step_count() const noexcept
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_buffers() noexcept(noexcept(cur_.swap(nxt_)))
O(1) swap of the two buffers (called by double-buffer schemes).
const Neighborhood & neighborhood() const noexcept
const Update_Scheme & scheme() const noexcept
typename Lattice::extents_type extents_type
Async_Engine & operator=(const Async_Engine &other)=default
Copy another engine into this one: its lattices, its rule, its neighborhood, its update scheme,...
void on_post_step(F &&f)
Register a hook fired after every step().
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.
Lattice & next_buffer() noexcept
void step()
Run one engine step using the configured update scheme.
void set_step_count(const std::size_t s) noexcept
Override the completed-step counter.
void on_pre_step(F &&f)
Register a hook fired before every step().
Async_Engine(Lattice initial, Rule r, Update_Scheme s={})
Build an engine with a default-constructed neighborhood.
void run_back(const std::size_t steps)
Reverse several steps (Margolus only).
void swap_all_or_none(Async_Engine &other)
typename Lattice::coord_type coord_type
std::size_t steps_run() const noexcept
std::function< void(std::size_t, const Lattice &)> hook_type
Hook signature: (step_index, frame).
const Lattice & current_buffer() const noexcept
typename Lattice::state_type state_type
Update_Scheme scheme_type
void run(const std::size_t steps)
Run several steps.
Async_Engine(Lattice initial, Rule r, Neighborhood n, Update_Scheme s={})
Build an engine.
Lattice & write_lattice() noexcept
Alias for current_buffer(). Used by checkpoint restore.
const extents_type & extents() const noexcept
static constexpr std::size_t rank
Lattice dimension.
Async_Engine(const Async_Engine &other)=default
Copy another engine: its lattices, its rule, its neighborhood, its update scheme, its hooks and its c...
Neighborhood neighborhood_type
const Rule & rule() const noexcept
Lattice that adds boundary-aware access on top of a storage.
typename Storage::state_type state_type
typename Storage::extents_type extents_type
const extents_type & extents() const noexcept
void swap(Lattice &other) noexcept(noexcept(store_.swap(other.store_)))
O(1) swap.
typename Storage::coord_type coord_type
static constexpr std::size_t rank
Placeholder neighbourhood for engines that drive block rules.
static constexpr std::size_t size_v
Empty neighbourhood: zero offsets.
static constexpr std::size_t radius() noexcept
Always returns 0 (no offsets).
static constexpr void for_each_offset(const coord_type &, F &&) noexcept
No-op: the neighbourhood is empty.
static constexpr std::size_t rank_v
Lattice dimension.
static constexpr std::size_t radius_v
Compile-time radius (zero, since the neighbourhood is empty).
static constexpr std::size_t size() noexcept
Always returns 0 (no offsets).
Coord_Vec< Rank > coord_type
Coordinate type accepted by for_each_offset.
Detect whether a lattice exposes a refresh_halo() method (the hallmark of a Ghost_Lattice or any othe...
Storage + topology that carries the cell values.
Connectivity pattern around a coordinate.
Detect whether the scheme exposes apply_with_origin(engine, rule, origin) (Margolus).
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
C++20 concepts for the Cellular Automata module.
Neighborhoods catalogue for Aleph::CA.
Phase 13 update-scheme strategies for Aleph::CA.