58#include <gtest/gtest.h>
84 for (std::size_t i = 0; i < 5; ++i)
120 std::array<ca_size_t, 2>
ext{17, 9};
121 std::vector<int> hits(
ext[0], 0);
122 for (std::size_t p = 0; p < 5; ++p)
134 std::array<ca_size_t, 2>
ext{12, 18};
138 std::vector<std::vector<int>> hits(
ext[0], std::vector<int>(
ext[1], 0));
139 for (std::size_t t = 0; t < 6; ++t)
142 for (
ca_size_t i = tile.rows.begin; i < tile.rows.end; ++i)
143 for (
ca_size_t j = tile.cols.begin; j < tile.cols.end; ++j)
146 for (
const auto &
row : hits)
179 using coord_t =
typename L::coord_type;
180 if constexpr (L::rank == 1)
186 else if constexpr (L::rank == 2)
195 else if constexpr (L::rank == 3)
213 if (a.extents() != b.extents())
215 using coord_t =
typename L::coord_type;
216 if constexpr (L::rank == 1)
220 if (a.at(
coord_t{static_cast<ca_index_t>(i)})
224 else if constexpr (L::rank == 2)
232 if (a.at(c) != b.at(c))
236 else if constexpr (L::rank == 3)
248 if (a.at(c) != b.at(c))
257template <
typename Lattice,
typename Rule,
typename Neighborhood>
263 std::size_t partitions,
279 <<
"Parallel engine diverged from sequential at " <<
steps <<
" steps with "
280 << partitions <<
" partitions";
293 for (std::size_t
parts : {1u, 2u, 4u, 8u})
303 for (std::size_t
parts : {1u, 2u, 4u})
313 for (std::size_t
parts : {1u, 3u, 8u})
323 for (std::size_t
parts : {1u, 2u, 4u})
333 for (std::size_t
parts : {1u, 4u, 8u})
343 for (std::size_t
parts : {1u, 2u, 4u, 8u})
353 for (std::size_t
parts : {1u, 4u})
367 for (std::size_t
parts : {1u, 2u, 8u})
385 cfg.min_parallel_cells = 0;
400 for (std::uint8_t
rule_no : {std::uint8_t{30}, std::uint8_t{90}, std::uint8_t{110}})
403 seed.set(
typename L::coord_type{128}, 1);
406 for (std::size_t
parts : {1u, 2u, 4u, 8u})
414 L seed({12, 12, 12}, 0);
419 +[](
int current, std::size_t alive) ->
int {
426 for (std::size_t
parts : {1u, 2u, 4u})
448 cfg.min_parallel_cells = 1024;
468 cfg.min_parallel_cells = 0;
480 par.on_post_step([&](std::size_t
step_idx,
const L &) {
502 cfg.num_partitions = 4;
503 cfg.min_parallel_cells = 0;
525 cfg.min_parallel_cells = 0;
551 cfg.min_parallel_cells = 0;
576 for (std::size_t
parts : {1u, 2u, 5u, 8u})
580 cfg.min_parallel_cells = 0;
585 <<
"Blinker did not return to seed with " <<
parts <<
" partitions";
607 L seed({33, 32},
false);
615 cfg.min_parallel_cells = 0;
size_t size_t int32_t * out
Domain-decomposition utilities for the parallel CA engine.
Common typedefs and tag types for the Cellular Automata module.
User-supplied list of offsets for arbitrary connectivity.
Lattice with Halo ghost layers around the user-visible cells.
Lattice that adds boundary-aware access on top of a storage.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Parallel synchronous double-buffered engine.
std::size_t steps_run() const noexcept
Return the number of completed steps.
void run(const std::size_t steps)
Run several synchronous steps.
const Lattice & frame() const noexcept
Return the current frame.
void on_pre_step(F &&f)
Register a hook fired before every step().
Synchronous double-buffered engine.
void run(const std::size_t steps)
Run several synchronous steps.
std::size_t steps_run() const noexcept
Return the number of completed steps.
const Lattice & frame() const noexcept
Return the current frame.
Von Neumann (L1) neighborhood of radius R in N dimensions.
A reusable thread pool for efficient parallel task execution.
Minimal std::expected-style result type for C++20.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
constexpr Range1D split_range_balanced(const ca_size_t n, const ca_size_t parts, const ca_size_t idx) noexcept
Balanced split of [0, n) into parts contiguous ranges.
double density(const Lattice &lat, const typename Lattice::state_type &s)
bool frames_equal(const Lattice &a, const Lattice &b)
constexpr bool should_run_sequential(const ca_size_t cells, const ca_size_t num_partitions, const ca_size_t min_cells) noexcept
Decide whether a workload should run sequentially.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Coord_Vec< N > Offset_Vec
Default offset vector (aliases Coord_Vec).
constexpr std::uint64_t morton_encode_2d(const std::uint32_t x, const std::uint32_t y) noexcept
Morton (Z-order) encoding of (x, y).
constexpr Lookup_Rule< 2, 2 > make_wolfram_elementary_rule(std::uint8_t rule_no) noexcept
Build the elementary 1D Wolfram rule rule_no (0..255) as a Lookup_Rule<2, 2> over neighbourhood {-1,...
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static constexpr Tile2D_Range tile(const std::array< ca_size_t, 2 > &extents, const ca_size_t parts_y, const ca_size_t parts_x, const ca_size_t tile_index) noexcept
Tile owned by tile_index over the parts_y * parts_x grid.
static constexpr std::array< ca_size_t, 2 > factor_partitions(const std::array< ca_size_t, 2 > &extents, const ca_size_t parts) noexcept
Pick a balanced (parts_y, parts_x) factorisation of parts.
Zero-gradient (Neumann) boundary.
Out-of-range neighbours behave as if the lattice ended.
Configuration for Parallel_Synchronous_Engine.
std::size_t num_partitions
Number of partitions per step.
ThreadPool * pool
Thread pool to schedule on. nullptr means Aleph::default_pool().
Out-of-range coordinates mirror back into the lattice.
static constexpr Range1D slab(const std::array< ca_size_t, Rank > &extents, const ca_size_t parts, const ca_size_t idx) noexcept
Number of partitions along axis 0 with a balanced split.
Iterate a 2D lattice in W x H tiles.
The lattice wraps around on every axis.
A modern, efficient thread pool for parallel task execution.
Bit-packed dense storage for boolean cellular automata.
C++20 concepts for the Cellular Automata module.
Synchronous double-buffered engine for cellular automata.
Ghost-layer lattice for high-performance boundary handling.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Parallel synchronous engine for cellular automata (Phase 5).
static void seed_random(L &lat, std::uint32_t seed, double density=0.4)
static void expect_engine_equivalence(const Lattice &seed, Rule rule, Neighborhood nh, std::size_t steps, std::size_t partitions, std::size_t min_cells=0)
Rule mechanisms for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).