Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
static_executor.hpp
Go to the documentation of this file.
1#pragma once
2
25
26#include <cstdint>
27#include <string_view>
28#include <vector>
29
34#include "orrery/core/types.hpp"
35
36namespace orrery::backend {
37
39class StaticExecutor final : public Executor {
40public:
45 explicit StaticExecutor(unsigned worker_count = 0,
47
48 void run(core::Index count, RangeTask task) override;
49
50 [[nodiscard]] std::string_view name() const noexcept override { return "static"; }
51
52 [[nodiscard]] unsigned worker_count() const noexcept override { return pool_.worker_count(); }
53
54 [[nodiscard]] CoreClass worker_core_class(unsigned worker) const noexcept override {
55 return pool_.core_class(worker);
56 }
57
58 [[nodiscard]] ExecutorStatistics statistics() const override;
59
60 void reset_statistics() noexcept override;
61
62private:
63 ThreadPool pool_;
64
67 std::vector<PaddedWorkerStatistics> workers_;
68
72 std::vector<Duration> busy_at_region_start_;
73
74 Duration elapsed_{};
75 std::uint64_t regions_{};
76};
77
78} // namespace orrery::backend
unsigned worker_count() const noexcept override
How many workers this executor divides work between.
Definition static_executor.hpp:52
std::string_view name() const noexcept override
The scheme's name, for benchmark tables and reports.
Definition static_executor.hpp:50
ExecutorStatistics statistics() const override
The record of what the workers have done since the last reset.
void reset_statistics() noexcept override
Set every counter back to zero.
StaticExecutor(unsigned worker_count=0, ThreadPool::Affinity affinity=ThreadPool::Affinity::kUnpinned)
One worker per logical processor unless told otherwise.
void run(core::Index count, RangeTask task) override
Call task over pieces that together cover [0, count) exactly once each, and return when all of them h...
CoreClass worker_core_class(unsigned worker) const noexcept override
What kind of core a worker runs on, where that is known.
Definition static_executor.hpp:54
Worker threads and a way to run something on all of them at once.
Definition thread_pool.hpp:41
Affinity
Whether workers are tied to a particular logical processor.
Definition thread_pool.hpp:44
@ kUnpinned
Let the operating system place the threads.
Definition thread_pool.hpp:51
Which logical processors this machine has, and which of them are fast.
CoreClass
What kind of core a logical processor belongs to.
Definition cpu_topology.hpp:47
How a kernel asks for a loop to be run in parallel.
core::FunctionRef< void(core::Index, core::Index)> RangeTask
A piece of a parallel loop: the half-open index range [begin, end).
Definition executor.hpp:49
The whole pool's record.
Definition worker_statistics.hpp:99
One worker's record, on a cache line of its own.
Definition worker_statistics.hpp:94
A fixed set of worker threads that run one body function on demand.
The scalar and index types that every layer of the project agrees on.
std::size_t Index
The type of a particle index and of any count of particles.
Definition types.hpp:45
What each worker thread did, and how long it spent doing nothing.
std::chrono::nanoseconds Duration
Durations are stored in nanoseconds so that they add without conversion and mean the same thing on ev...
Definition worker_statistics.hpp:53