SPH
Tbb.h
Go to the documentation of this file.
1 #pragma once
2 
7 
9 #include "thread/Scheduler.h"
10 
12 
13 struct TbbData;
14 
18 class Tbb : public IScheduler {
19 private:
21 
22  static SharedPtr<Tbb> globalInstance;
23 
24 public:
25  Tbb(const Size numThreads = 0, const Size granularity = 1000);
26 
27  ~Tbb();
28 
29  void setGranularity(const Size newGranularity);
30 
31  void setThreadCnt(const Size numThreads);
32 
33  virtual SharedPtr<ITask> submit(const Function<void()>& task) override;
34 
35  virtual Optional<Size> getThreadIdx() const override;
36 
37  virtual Size getThreadCnt() const override;
38 
39  virtual Size getRecommendedGranularity() const override;
40 
41  virtual void parallelFor(const Size from,
42  const Size to,
43  const Size granularity,
44  const Function<void(Size n1, Size n2)>& functor) override;
45 
47 };
48 
49 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define NAMESPACE_SPH_END
Definition: Object.h:12
Wrapper of another pointer-like object with reference-like const correctness.
Interface for executing tasks (potentially) asynchronously.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Const-propagating wrapper for object with point semantics.
Scheduler encapsulating Intel Thread Building Blocks (TBB).
Definition: Tbb.h:18
virtual Optional< Size > getThreadIdx() const override
Returns the index of the calling thread.
void setGranularity(const Size newGranularity)
virtual void parallelFor(const Size from, const Size to, const Size granularity, const Function< void(Size n1, Size n2)> &functor) override
Processes the given range concurrently.
void setThreadCnt(const Size numThreads)
Tbb(const Size numThreads=0, const Size granularity=1000)
~Tbb()
virtual Size getThreadCnt() const override
Returns the number of threads used by this scheduler.
virtual SharedPtr< ITask > submit(const Function< void()> &task) override
Submits a task to be potentially executed asynchronously.
static SharedPtr< Tbb > getGlobalInstance()
virtual Size getRecommendedGranularity() const override
Returns a value of granularity that is expected to perform well with the current thread count.