SPH
OpenMp.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "thread/Scheduler.h"
4 
6 
10 class OmpScheduler : public IScheduler {
11 private:
12  static SharedPtr<OmpScheduler> globalInstance;
13 
14  Size granularity = 100;
15 
16 public:
17  OmpScheduler(const Size numThreads = 0);
18 
19  void setGranularity(const Size newGranularity) {
20  granularity = newGranularity;
21  }
22 
23  virtual SharedPtr<ITask> submit(const Function<void()>& task) override;
24 
25  virtual Optional<Size> getThreadIdx() const override;
26 
27  virtual Size getThreadCnt() const override;
28 
29  virtual Size getRecommendedGranularity() const override;
30 
31  virtual void parallelFor(const Size from,
32  const Size to,
33  const Size granularity,
34  const Function<void(Size n1, Size n2)>& functor) override;
35 
37 };
38 
39 
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
Interface for executing tasks (potentially) asynchronously.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
Scheduler encapsulating OpenMP directives.
Definition: OpenMp.h:10
virtual SharedPtr< ITask > submit(const Function< void()> &task) override
Submits a task to be potentially executed asynchronously.
OmpScheduler(const Size numThreads=0)
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.
virtual Size getRecommendedGranularity() const override
Returns a value of granularity that is expected to perform well with the current thread count.
static SharedPtr< OmpScheduler > getGlobalInstance()
virtual Optional< Size > getThreadIdx() const override
Returns the index of the calling thread.
virtual Size getThreadCnt() const override
Returns the number of threads used by this scheduler.
void setGranularity(const Size newGranularity)
Definition: OpenMp.h:19