70Lat_t make_random_seed(std::size_t n, std::uint32_t
seed)
74 std::bernoulli_distribution flip(0.4);
75 for (std::size_t i = 0; i < n; ++i)
76 for (std::size_t j = 0; j < n; ++j)
77 lat.set({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)},
86 for (std::size_t i = 0; i < a.
size(0); ++i)
87 for (std::size_t j = 0; j < a.
size(1); ++j)
88 if (a.
at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)})
89 != b.
at({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)}))
115 out_frame = eng.frame();
123 std::printf(
"Aleph::CA Phase-5 microbench (Game of Life, toroidal)\n");
124 std::printf(
"------------------------------------------------------\n");
125 std::printf(
"hardware_concurrency = %u\n",
126 static_cast<unsigned>(std::thread::hardware_concurrency()));
130 const std::array<std::size_t, 3> sizes{256, 512, 1024};
131 const std::array<std::size_t, 5> thread_counts{1, 2, 4, 8, 16};
132 const std::size_t
steps = 100;
135 "\n%-7s %-9s %-9s %-18s %-9s\n",
"N",
"threads",
"wall (s)",
"throughput",
"speedup");
136 std::printf(
"%-7s %-9s %-9s %-18s %-9s\n",
"-------",
"-------",
"--------",
137 "-----------------",
"-------");
139 for (std::size_t
N : sizes)
141 const Lat_t seed = make_random_seed(
N, 0xCAFEu ^
N);
148 const double seq_throughput
149 =
static_cast<double>(
N) *
N *
steps / seq_seconds;
151 std::printf(
"%-7zu %-9s %-9.4f %-18s %-9s\n",
158 for (std::size_t
T : thread_counts)
161 const double par_seconds = run_parallel(
seed,
steps,
T, par_frame);
165 std::printf(
" *** divergence at N=%zu T=%zu ***\n",
N,
T);
169 const double throughput
170 =
static_cast<double>(
N) *
N *
steps / par_seconds;
171 const double speedup = seq_seconds / par_seconds;
172 std::printf(
"%-7zu %-9zu %-9.4f %-18s %4.2fx\n",
189 (void)run_sequential;
191 std::printf(
"Microbench finished. All parallel runs matched the sequential frame.\n");
Tiny chrono-based timer used by the CA module Examples.
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
const extents_type & extents() const noexcept
ca_size_t size() const noexcept
state_type at(const coord_type &c) const
Strict access: throws if c is out of range.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Parallel synchronous double-buffered engine.
Synchronous double-buffered engine.
Number Theoretic Transform over Z / MOD Z.
A reusable thread pool for efficient parallel task execution.
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
const char * format_throughput(double cells_per_second)
Format a "cells per second" rate as "X.XX M cells/s".
bool frames_equal(const Lattice &a, const Lattice &b)
double bench_seconds(F &&f)
Run f() once and return the wall-clock time it took, in seconds.
Main namespace for Aleph-w library functions.
ThreadPool & default_pool()
Return the default shared thread pool instance.
std::decay_t< typename HeadC::Item_Type > T
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().
std::size_t min_parallel_cells
Workloads with fewer cells than this are executed sequentially without touching the pool.
The lattice wraps around on every axis.
A modern, efficient thread pool for parallel task execution.
Synchronous double-buffered engine for cellular automata.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Parallel synchronous engine for cellular automata (Phase 5).
Rule mechanisms for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).