Go to the documentation of this file.
10 #ifndef EIGEN_CXX11_THREADPOOL_NONBLOCKING_THREAD_POOL_H
11 #define EIGEN_CXX11_THREADPOOL_NONBLOCKING_THREAD_POOL_H
15 template <
typename Environment>
18 typedef typename Environment::Task
Task;
25 Environment
env = Environment())
51 #ifndef EIGEN_THREAD_LOCAL
58 env_.CreateThread([
this,
i]() { WorkerLoop(i); }));
60 #ifndef EIGEN_THREAD_LOCAL
93 const auto& pair = partitions[
i];
94 unsigned start = pair.first,
end = pair.second;
106 int limit)
override {
109 if (
pt->pool ==
this) {
112 t =
q.PushFront(std::move(
t));
118 int num_queues = limit - start;
119 int rnd =
Rand(&
pt->rand) % num_queues;
122 t =
q.PushBack(std::move(
t));
143 #ifdef EIGEN_THREAD_ENV_SUPPORTS_CANCELLATION
157 if (
pt->pool ==
this) {
158 return pt->thread_id;
192 thread_data_[
i].steal_partition.store(val, std::memory_order_relaxed);
196 return thread_data_[
i].steal_partition.load(std::memory_order_relaxed);
200 for (
int i = 1;
i <=
N;
i++) {
215 typedef typename Environment::EnvThread
Thread;
222 #ifndef EIGEN_THREAD_LOCAL
247 #ifndef EIGEN_THREAD_LOCAL
255 #ifndef EIGEN_THREAD_LOCAL
256 std::unique_ptr<PerThread> new_pt(
new PerThread());
268 pt->thread_id = thread_id;
275 const int spin_count =
286 for (
int i = 0;
i < spin_count && !
t.f;
i++) {
287 if (!
cancelled_.load(std::memory_order_relaxed)) {
310 for (
int i = 0;
i < spin_count && !
t.f;
i++) {
311 if (!
cancelled_.load(std::memory_order_relaxed)) {
338 const size_t size = limit - start;
339 unsigned r =
Rand(&
pt->rand);
347 for (
unsigned i = 0;
i <
size;
i++) {
354 if (victim >=
size) {
368 unsigned start, limit;
372 return Steal(start, limit);
437 unsigned r =
Rand(&
pt->rand);
439 unsigned victim = r %
size;
440 for (
unsigned i = 0;
i <
size;
i++) {
445 if (victim >=
size) {
453 return std::hash<std::thread::id>()(std::this_thread::get_id());
457 #ifndef EIGEN_THREAD_LOCAL
463 return it->second.get();
466 EIGEN_THREAD_LOCAL
PerThread per_thread_;
475 *
state = current * 6364136223846793005ULL + 0xda3e39cb94b95bdbULL;
477 return static_cast<unsigned>((current ^ (current >> 22)) >>
478 (22 + (current >> 61)));
486 #endif // EIGEN_CXX11_THREADPOOL_NONBLOCKING_THREAD_POOL_H
int CurrentThreadId() const EIGEN_FINAL
std::atomic< bool > spinning_
Namespace containing all symbols from the Eigen library.
void SetStealPartitions(const std::vector< std::pair< unsigned, unsigned >> &partitions)
Environment::EnvThread Thread
#define eigen_plain_assert(x)
void ComputeCoprimes(int N, MaxSizeVector< unsigned > *coprimes)
static const Point3 pt(1.0, 2.0, 3.0)
ThreadPoolTempl(int num_threads, Environment env=Environment())
bool WaitForWork(EventCount::Waiter *waiter, Task *t)
std::atomic< bool > cancelled_
ThreadPoolTempl(int num_threads, bool allow_spinning, Environment env=Environment())
MaxSizeVector< ThreadData > thread_data_
static EIGEN_STRONG_INLINE unsigned Rand(uint64_t *state)
std::unique_ptr< Barrier > init_barrier_
void ScheduleWithHint(std::function< void()> fn, int start, int limit) override
#define EIGEN_UNUSED_VARIABLE(var)
std::atomic< unsigned > blocked_
EIGEN_DEVICE_FUNC const Scalar & q
static const int kMaxThreads
void Schedule(std::function< void()> fn) EIGEN_OVERRIDE
std::unique_ptr< Thread > thread
MaxSizeVector< EventCount::Waiter > waiters_
#define EIGEN_STRONG_INLINE
unsigned EncodePartition(unsigned start, unsigned limit)
int NumThreads() const EIGEN_FINAL
void WorkerLoop(int thread_id)
unsigned global_steal_partition_
std::atomic< unsigned > steal_partition
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void push_back(const T &t)
unsigned GetStealPartition(int i)
MaxSizeVector< MaxSizeVector< unsigned > > all_coprimes_
ThreadPoolTempl< StlThreadEnvironment > ThreadPool
void Notify(bool notifyAll)
std::atomic< bool > done_
const bool allow_spinning_
static const int kMaxPartitionBits
static EIGEN_STRONG_INLINE uint64_t GlobalThreadIdHash()
void DecodePartition(unsigned val, unsigned *start, unsigned *limit)
void CommitWait(Waiter *w)
void AssertBounds(int start, int end)
void SetStealPartition(size_t i, unsigned val)
std::mutex per_thread_map_mutex_
void Cancel() EIGEN_OVERRIDE
RunQueue< Task, 1024 > Queue
unsigned __int64 uint64_t
static const EIGEN_DEPRECATED end_t end
std::unordered_map< uint64_t, std::unique_ptr< PerThread > > per_thread_map_
Task Steal(unsigned start, unsigned limit)
EIGEN_STRONG_INLINE PerThread * GetPerThread()
gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:02:02