Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
bench_multi_field_lv.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11*/
12
18#include <cstddef>
19#include <cstdint>
20#include <tuple>
21
23#include <ca-traits.H>
26#include <tpl_ca_neighborhood.H>
27
28using namespace Aleph::CA;
29using namespace Aleph::CA::Bench;
30
31namespace
32{
33
35
37class Lotka_Volterra_Rule
38{
39 double alpha_, beta_, delta_, gamma_, dt_, diff_;
40
41public:
42 Lotka_Volterra_Rule(double alpha, double beta, double delta, double gamma,
43 double dt, double diffusion)
44 : alpha_(alpha), beta_(beta), delta_(delta), gamma_(gamma), dt_(dt),
45 diff_(diffusion)
46 {}
47
48 std::tuple<double, double>
49 operator()(const std::tuple<double, double> &cur,
50 const std::tuple<Neighbor_View<double>, Neighbor_View<double>> &nb) const
51 {
52 const double x = std::get<0>(cur);
53 const double y = std::get<1>(cur);
54 double lap_x = -static_cast<double>(std::get<0>(nb).size()) * x;
55 double lap_y = -static_cast<double>(std::get<1>(nb).size()) * y;
56 for (const auto &p : std::get<0>(nb)) lap_x += p;
57 for (const auto &p : std::get<1>(nb)) lap_y += p;
58 const double next_x = x + dt_ * (alpha_ * x - beta_ * x * y + diff_ * lap_x);
59 const double next_y = y + dt_ * (delta_ * x * y - gamma_ * y + diff_ * lap_y);
60 return {next_x < 0.0 ? 0.0 : next_x, next_y < 0.0 ? 0.0 : next_y};
61 }
62};
63
68Grid make_seed(const ca_size_t side)
69{
70 Grid lat({side, side});
71 lat.fill(std::tuple{1.0, 0.5});
72 const ca_size_t cr = lat.size(0) / 2;
73 const ca_size_t cc = lat.size(1) / 2;
74 for (ca_size_t i = cr - 1; i <= cr + 1; ++i)
75 for (ca_size_t j = cc - 1; j <= cc + 1; ++j)
76 {
77 const Coord_Vec<2> c{static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)};
78 lat.set<0>(c, 1.5);
79 lat.set<1>(c, 0.8);
80 }
81 return lat;
82}
83
84} // namespace
85
86int main()
87{
88 constexpr ca_size_t side = 512;
89 constexpr std::size_t steps = 500;
90 const double processed_cells
91 = static_cast<double>(side) * static_cast<double>(side) * static_cast<double>(steps);
92
93 const Bench_Result result = measure("multi_field_lv_512", processed_cells, resolve_repeats(3), [&]
94 {
97 Lotka_Volterra_Rule{/*alpha=*/1.0, /*beta=*/0.5, /*delta=*/0.4,
98 /*gamma=*/0.5, /*dt=*/0.05, /*diff=*/0.05},
101 });
102
103 emit_json(result);
104 return 0;
105}
int main()
Shared harness for the cellular-automata performance-gate anchors.
size_t steps
Definition ca-c-api.h:126
Common typedefs and tag types for the Cellular Automata module.
Synchronous double-buffered engine for multi-field lattices.
void run(const std::size_t steps)
Run several steps.
Multi-field lattice with selectable storage layout.
Von Neumann (L1) neighborhood of radius R in N dimensions.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_gamma_function > > gamma(const __gmp_expr< T, U > &expr)
Definition gmpfrxx.h:4103
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
static mpfr_t y
Definition mpfr_mul_d.c:3
std::size_t resolve_repeats(const std::size_t fallback)
Resolve the number of timed repetitions for one anchor.
void emit_json(const Bench_Result &result, std::ostream &out=std::cout)
Print one benchmark result as a single structured JSON object.
Bench_Result measure(std::string name, const double processed_cells, std::size_t repeats, Work &&work)
Time a kernel with one warmup pass plus a median of timed passes.
constexpr std::uint32_t delta
File contains only the cells that changed relative to a baseline.
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
Definition ca-traits.H:90
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
Definition ca-traits.H:60
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
Definition ca-traits.H:69
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Definition ca-traits.H:63
STL namespace.
Outcome of one measured anchor benchmark.
static mt19937 engine
Phase 14 synchronous double-buffered engine for multi-field cellular automata.
Phase 14 multi-field cellular automata lattice (AoS / SoA).
Neighborhoods catalogue for Aleph::CA.