Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Per_Thread_RNG< Engine > Class Template Reference

Master seed dispenser for stochastic CA rules. More...

#include <ca-rng.H>

Public Types

using engine_type = Engine
 Underlying engine type.
 
using result_type = typename Engine::result_type
 Result type of engine_type.
 

Public Member Functions

constexpr Per_Thread_RNG (const std::uint64_t seed=0) noexcept
 Build a dispenser around seed.
 
constexpr std::uint64_t master_seed () const noexcept
 Return the master seed.
 
template<std::size_t Rank>
Engine for_cell (const std::size_t step, const Coord_Vec< Rank > &coord) const
 Build a fresh deterministic engine for cell (step, coord).
 
template<std::size_t Rank>
Engine for_cell (const Cell_Context< Rank > &ctx) const
 Build a fresh deterministic engine from a Cell_Context.
 
Engine for_thread_step (const std::size_t thread_id, const std::size_t step) const
 Build an engine for a (thread, step) sub-stream.
 

Private Attributes

std::uint64_t master_
 

Detailed Description

template<typename Engine = std::mt19937_64>
class Aleph::CA::Per_Thread_RNG< Engine >

Master seed dispenser for stochastic CA rules.

Per_Thread_RNG does not own any RNG state: it is a pure factory that builds a fresh deterministic engine on demand from a master seed and either a per-cell context or a per-thread descriptor. This makes it cheap to copy, share between threads (no synchronisation required) and to compose with the Phase 5 parallel engine without serialisation hazards.

Typical usage inside a contextual rule:

double p; std::uint64_t master;
template <typename State, std::size_t Rank>
State operator()(const State& s, Neighbor_View<State> v,
const Cell_Context<Rank>& ctx) const {
auto eng = rng.for_cell(ctx);
return uniform_unit(eng) < p ? next(s, v) : s;
}
};
Master seed dispenser for stochastic CA rules.
Definition ca-rng.H:274
static mt19937 rng
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
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
Definition ca-traits.H:90
double uniform_unit(Engine &eng)
Map a 64-bit RNG output to a uniform value in [0, 1).
Definition ca-rng.H:206
void next()
Advance all underlying iterators (bounds-checked).
Definition ah-zip.H:171
Per-cell context handed to rules that need to know "where" and "when" they are firing.
Definition ca-traits.H:106
Template Parameters
EnginePRNG engine type. Defaults to std::mt19937_64 for its 64-bit output and good statistical quality. Any engine whose result_type is unsigned and at least 53 bits wide works.

Definition at line 273 of file ca-rng.H.

Member Typedef Documentation

◆ engine_type

template<typename Engine = std::mt19937_64>
using Aleph::CA::Per_Thread_RNG< Engine >::engine_type = Engine

Underlying engine type.

Definition at line 279 of file ca-rng.H.

◆ result_type

template<typename Engine = std::mt19937_64>
using Aleph::CA::Per_Thread_RNG< Engine >::result_type = typename Engine::result_type

Result type of engine_type.

Definition at line 281 of file ca-rng.H.

Constructor & Destructor Documentation

◆ Per_Thread_RNG()

template<typename Engine = std::mt19937_64>
constexpr Aleph::CA::Per_Thread_RNG< Engine >::Per_Thread_RNG ( const std::uint64_t  seed = 0)
inlineexplicitconstexprnoexcept

Build a dispenser around seed.

Parameters
[in]seedmaster seed reused across every sub-stream.
Exceptions
Thisfunction does not throw.

Definition at line 288 of file ca-rng.H.

Member Function Documentation

◆ for_cell() [1/2]

template<typename Engine = std::mt19937_64>
template<std::size_t Rank>
Engine Aleph::CA::Per_Thread_RNG< Engine >::for_cell ( const Cell_Context< Rank > &  ctx) const
inline

Build a fresh deterministic engine from a Cell_Context.

Template Parameters
Rankcoordinate rank (deduced).
Parameters
[in]ctxper-cell context produced by the engine.
Returns
engine seeded with cell_seed(master_, ctx).
Exceptions
Anyexception thrown by Engine's constructor.

Definition at line 325 of file ca-rng.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Cell_Context< Rank >::coord, and Aleph::CA::Cell_Context< Rank >::step.

◆ for_cell() [2/2]

template<typename Engine = std::mt19937_64>
template<std::size_t Rank>
Engine Aleph::CA::Per_Thread_RNG< Engine >::for_cell ( const std::size_t  step,
const Coord_Vec< Rank > &  coord 
) const
inline

Build a fresh deterministic engine for cell (step, coord).

The returned engine state depends only on (master_, step, coord), so two calls with the same arguments — possibly from different threads — produce identical streams.

Template Parameters
Rankcoordinate rank (deduced).
Parameters
[in]stepstep index being evaluated.
[in]coordcell coordinate.
Returns
engine seeded with cell_seed(master_, step, coord).
Exceptions
Anyexception thrown by Engine's constructor.

Definition at line 312 of file ca-rng.H.

References Aleph::blossom_maximum_cardinality_matching(), and Aleph::CA::Per_Thread_RNG< Engine >::master_.

◆ for_thread_step()

template<typename Engine = std::mt19937_64>
Engine Aleph::CA::Per_Thread_RNG< Engine >::for_thread_step ( const std::size_t  thread_id,
const std::size_t  step 
) const
inline

Build an engine for a (thread, step) sub-stream.

The result depends on (master_, thread_id, step) and is therefore not invariant under different thread counts. Use this overload only when you explicitly want a per-thread sub-stream rather than per-cell determinism.

Parameters
[in]thread_idstable identifier for the worker.
[in]stepstep index being evaluated.
Returns
engine seeded with thread_step_seed.
Exceptions
Anyexception thrown by Engine's constructor.

Definition at line 342 of file ca-rng.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Per_Thread_RNG< Engine >::master_, and Aleph::CA::thread_step_seed().

◆ master_seed()

template<typename Engine = std::mt19937_64>
constexpr std::uint64_t Aleph::CA::Per_Thread_RNG< Engine >::master_seed ( ) const
inlineconstexprnoexcept

Return the master seed.

Returns
user-supplied master seed.
Exceptions
Thisfunction does not throw.

Definition at line 294 of file ca-rng.H.

References Aleph::CA::Per_Thread_RNG< Engine >::master_.

Member Data Documentation

◆ master_


The documentation for this class was generated from the following file: