Skip to content

Engine → Core

parallel_for.h

Convenience wrappers around job_system::parallel_for that accept any callable instead of a std::function. The wrapper std::function is built once per call and holds only references, so it stays within the small-object buffer and the dispatch remains allocation-free.

Functions

Public

jobs::default_grain

[[nodiscard]] constexpr usize default_grain(usize count, u32 workerCount) noexcept;

Grain used by the per-index parallel_for: max(1, count / (workerCount * 4)), treating zero workers as one.

jobs::parallel_for_each

template <typename ElementType, typename Body> void parallel_for_each(job_system &system, std::span<ElementType> items, usize grain, Body &&body);

Runs body(item) for every element of the span, grain elements per job.

template <typename ElementType, typename Body> void parallel_for_each(job_system &system, std::span<ElementType> items, Body &&body);

Runs body(item) for every element of the span with the default grain.

jobs::parallel_for_range

template <typename Body> void parallel_for_range(job_system &system, usize count, usize grain, Body &&body);

Runs body(begin, end) over [0, count) in ranges of at most grain elements.

jobs::range_count

[[nodiscard]] constexpr usize range_count(usize count, usize grain) noexcept;

Number of ranges [0, count) splits into with the given grain (a grain of 0 counts as 1).