group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Parallel.hpp File Reference

Thin wrapper around C++17 parallel STL. More...

#include <SDL3/SDL.h>
#include <algorithm>
#include <atomic>
#include <cstdlib>
Include dependency graph for Parallel.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  group2
namespace  group2::perf

Functions

void group2::perf::initParallelFromEnv ()
 Initialize from environment.
template<class Iter, class Fn>
void group2::perf::parallelFor (Iter begin, Iter end, Fn &&fn)
 Call fn(*it) for every element in [begin, end).

Variables

std::atomic< bool > group2::perf::parallelEnabled {true}
 Master switch for parallel execution.
constexpr std::size_t group2::perf::k_parallelThreshold = 64
 Minimum items below which parallelFor runs sequentially even when the master switch is on.

Detailed Description

Thin wrapper around C++17 parallel STL.

PR-3 (server-perf): the per-system game-thread work is largely embarrassingly parallel across players (animation update, hitbox capsule transform, swept collision, etc.). This header gives the systems a single, opinionated entry point — group2::perf::parallelFor(begin, end, fn) — that hides the libstdc++ parallel-STL details.

Implementation policy:

  • On Linux with TBB installed (the common dev / CI path), we route through std::for_each(std::execution::par_unseq, ...), which libstdc++ implements via TBB's task-group scheduler.
  • On platforms without TBB (currently a CMake fallback path: macOS Homebrew without explicit install, some Linux distros), we fall back to a sequential std::for_each so behaviour stays correct and the build still links. CMake defines GROUP2_HAVE_TBB when the parallel path is wired.

Determinism: lag-comp + hitscan rely on the simulation being deterministic across the network/recording boundary. par_unseq reorders operations across iterations BUT operates only on independent per-entity slots, so the observable result is identical to a sequential pass. We add a GROUP2_SERVER_PARALLEL=0 kill-switch (read once at startup) to fall back to sequential if a regression turns up — the brain wants the diff to be exactly "thread count" so repro is easy.